Sometimes you found that you have committed some wrong files for in-completed code in your local git repository. The following command will revert the last commit in your current working repository. If you just want to change last commit message, you can use this article to do it.
Advertisement
Undo the Last Local Commit in Git
The git reset
is used to reset the index entries and updates files in the working tree that are different between the <commit>
and HEAD
.
- So use the following command to reset the index to
HEAD
and delete all changes in the local working copy.git reset --soft HEAD~
- Now, edit the local files make the necessary changes
- Add them again using git add command.
git add .
- After that commit files as you always do, you can reuse the old commit message using -c ORIG_HEAD. This will open last commit message in the editor.
git commit -c ORIG_HEAD
Wrap Up
In this tutorial, you have learned to reset the last commit from the local repository.