Git is a great VCS with an amazing data structure. I’m awestruck when I think about the fact that it was built in a weekend.

But I don’t like the syntax. Why does git checkout do so many things?

This is a personal reference to help me.

git diff
git diff -w
git diff --cached
git status
git checkout *branchname*
git checkout -b *branchname*
git checkout -- .
git clean -n
git clean -f
git fetch
git pull
git stash list
git stash show
git stash pop
git stash apply
git stash drop
git log

Undo an accidental commit

This is a complicated one. I recommend reading lots about git reset before ever using that command: https://git-scm.com/docs/git-reset

git reset --soft HEAD~1

The --soft flag means that the changes in the commit will be put back into the working directory as Changes to be committed. This means you can checkout another branch and make the commit there.

HEAD~1 means HEAD - 1, ie the second commit shown in git log.

Undo a failed git stash pop

git reset HEAD --hard

When a stash pop fails, the stash stays in the stash list. This will reset the working directory to the latest commit. If you have unsaved changes in the working directory apart from the stash contents, this might erase your data.

Undo a successful git stash pop

git stash

You just need to stash it again :)