Skip to content

Instantly share code, notes, and snippets.

@tkersey
Created October 8, 2010 22:36
Show Gist options
  • Save tkersey/617683 to your computer and use it in GitHub Desktop.
Save tkersey/617683 to your computer and use it in GitHub Desktop.
Git: undo a commit and redo
http://stackoverflow.com/questions/927358/git-undo-last-commit
Undo a commit and redo
$ git commit ...
$ git reset --soft HEAD^ (1)
$ edit (2)
$ git commit -a -c ORIG_HEAD (3)
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".
Make corrections to working tree files.
"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.
@tannewt
Copy link

tannewt commented Oct 21, 2016

This was super useful but beware that if you had files unstaged during the original commit they will be committed with the commit -a.

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