git

How to undo the last git commit?

There are situations where you just committed a change in git and just after that realized you made a mistake in the last git commit. If you haven’t pushed that code then the last local changes can be undone with the following command.

git reset --soft HEAD~1

What this does is that it uncommits the last git commit and puts that back in a staged state. That means if you run the git status command then you will see those changes in your working directory. Now you can make further changes to that revision and then commit again.

See the complete documentation about git-reset on the official site.

Read more posts about git here.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.