-
-
Save tkersey/617683 to your computer and use it in GitHub Desktop.
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. |
Glad helping myself helped you :)
Very useful. And this gist has been around a good while. Thanks! I didn't know about ORIG_HEAD.
Since I do this so often, I have found the following useful to add to my ~/.gitconfig:
[alias]
undo = reset --soft HEAD^
recommit = commit -a -c ORIG_HEAD
What if you revert a particular commit, then later want to re-commit the same changes?
e.g.:
commit 1
commit 2
commit 3
commit 4
commit 3 has some unfinished changes, but everything else needs pushed upstream. You can git revert 3
as long as that commit has nothing to do the the files you want to push. But the changes are in progress, and I don't want to permanently lose my place. Is there a way to get those particular changes back?
This was super useful but beware that if you had files unstaged during the original commit they will be committed with the commit -a
.
I actually could have used this earlier today. Starred, and thanks for posting Tim. :)