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.
Undo the Last Local Commit in Git
git reset is used to reset the index entries and updates files in the working tree that are different between the
- So use the following command to reset the index to
HEADand 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
In this tutorial, you have learned to reset the last commit from the local repository.