How to undo the last commit in Git?

Published December 30, 2020

To undo the last commit in Git, you can use the git reset command.

You have 2 ways to undo the last commit:

  • The first is the
git reset --soft HEAD~1

this command will undo the last commit. For most cases, this command can be used and safe to use. This command will also make sure to preserve the changes in uncommitted files.

  • The second one is the
git reset --hard HEAD~1

Will also undo the last commit but will not preserve the changes to uncommitted files and resets everything. Be cautious when using the above command.

Feel free to share if you found this useful 😃.

Share on: Facebook Twitter