Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Undo a commit & redo
git reset
is the command responsible for the undo. It will undo your last commit while leaving your working tree (the state of your files on disk) untouched. You’ll need to add them again before you can commit them again.git add
anything that you want to include in your new commit.reset
copied the old head to.git/ORIG_HEAD
;commit
with-c ORIG_HEAD
will 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-C
option.Alternatively, to edit the previous commit (or just its commit message),
commit --amend
will add changes within the current index to the previous commit.To remove (not revert) a commit that has been pushed to the server, rewriting history with
git push origin main --force[-with-lease]
is necessary. It’s almost always a bad idea to use--force
; prefer--force-with-lease
instead, and as noted in the git manual:Further Reading
You can use
git reflog
to determine the SHA-1 for the commit to which you wish to revert. Once you have this value, use the sequence of commands as explained above.HEAD~
is the same asHEAD~1
. The article What is the HEAD in git? is helpful if you want to uncommit multiple commits.