Undo the last commit but keep the changes

Committed too early? Take the commit back without losing any work.

SNP 020 #614 Filed git

The commit goes away, the changes stay staged:

shell
git reset --soft HEAD~1

If you want them unstaged as well, leave out --soft (the default is --mixed):

shell
git reset HEAD~1

And --hard throws the changes away too, so think twice before you type that one. Everything is still in git reflog for a while if you did.

Only do any of this on commits you haven't pushed yet. For a pushed commit, git revert HEAD creates a new commit that undoes it, which is the polite way.