Undo a commit and redo
$ git commit -m "Something terribly misguided" (1) $ git reset --soft HEAD~ (2) << edit files as necessary >> (3) $ git add ... (4) $ git commit -c ORIG_HEAD (5)
This is what you want to undo
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message1, or both. Leaves working tree as it was before
Make corrections to working tree files.
git addwhatever changes you want to include in your new commit.
Commit the changes, reusing the old commit message.
resetcopied the old head to
-c ORIG_HEADwill open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the
Editor's note 1: You don't need to reset to an earlier commit if "you misspelled your commit message". If you
reset, git will not link new activity to the previous commit in any way, giving you a blank slate for a new commit message. The easier option is
git commit --amend, which will open your default commit message editor pre-populated with the last commit message.
Beware however that if you have added any new changes to the index, using
commit --amend will add them to your previous commit.
You may find these answers helpful as well:
How to move HEAD back to a previous location? (Detached head)
How to uncommit my last commit in git