Skip to content

Instantly share code, notes, and snippets.

@stevepentler
Last active January 7, 2016 17:00
Show Gist options
  • Save stevepentler/28a56a6a78443d0065e7 to your computer and use it in GitHub Desktop.
Save stevepentler/28a56a6a78443d0065e7 to your computer and use it in GitHub Desktop.
Git
  • git stash -- Things are bad, real bad, and now you want to switch branches, BUT you don’t want to commit what you’ve been working on yet; so you’ll stash the changes. -- To push a new stash onto your stack, run git stash

  • git stash list -- To see which stashes you’ve stored, you can use git stash list

  • git stash apply -- In this case, two stashes were done previously, so you have access to three different stashed works. You can reapply the one you just stashed by using the command shown in the help output of the original stash command: git stash apply. If you want to apply one of the older stashes, you can specify it by naming it, like this: git stash apply stash@{2}

  • git shortlog -- produces easily palatable list of commit messages based on author -- ex: Steve Pentler (26): finished with partials and before_action cookies and sessions implemented. breaks when you try to delete a tool, probably an issue with the app implementing authentication, moving before action to application controller to start session first user authentication test passing - user_signs_up_for_account_test

  • git --ammend -- Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot. Running this when there is nothing staged lets you edit the previous commit’s message without altering its snapshot. -- ex: #####Edit hello.py and main.py *git add hello.py *git commit

#####Realize you forgot to add the changes from main.py *git add main.py *git commit --amend --no-edit

  • git reset --hard -- Resets the index and working tree. Any changes to tracked files in the working tree since are discarded.

  • git reset --soft -- Does not touch the index file or the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

  • git log -- --max-count= Limits the number of commits to output. -- --since= OR --after= Show commits more recent/before a specific date. -- ----author=

  • $ git reset --hard HEAD3 -- The last three commits (HEAD, HEAD^, and HEAD2) were bad and you do not want to ever see them again. Do not do this if you have already given these commits to somebody else. (See the "RECOVERING FROM UPSTREAM REBASE" section in git-rebase[1] for the implications of doing so.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment