DEV Community

Cover image for How to undo the last commit in Git?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to undo the last commit in Git?

Originally posted here!

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 😃.


Top comments (0)