Hi, I have committed some files which are not relevant to the project, So I need to undo the local commit. pls help.
Hi, I have committed some files which are not relevant to the project, So I need to undo the local commit. pls help.
$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~ # (1)
[ edit files as necessary ] # (2)
$ git add . # (3)
$ git commit -c ORIG_HEAD # (4)
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.Please refer to the Stackoverflow post for more details.
git revert <commit to revert>
git reset --soft HEAD~1
git reset --hard HEAD~1
You have to use the above commands to revert your recent changes.