Skip to content

Instantly share code, notes, and snippets.

@matuu
Created November 27, 2013 17:28
Show Gist options
  • Save matuu/7679707 to your computer and use it in GitHub Desktop.
Save matuu/7679707 to your computer and use it in GitHub Desktop.
Reset last commit
$ git commit ... (1)
$ git reset --soft "HEAD^" (2)
$ edit (3)
$ git add .... (4)
$ git commit -c ORIG_HEAD (5)
1) This is what you want to undo
2) This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset". (The quotes are required if you use zsh)
3) Make corrections to working tree files.
4) Stage changes for commit.
5) "reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.
Ref: http://stackoverflow.com/questions/927358/how-to-undo-the-last-git-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment