How to undo last commit using git reset?

There are many situations where you really want to undo the last commit.

Use soft reset:
Note the reset with –soft flag makes sure that the changes in undone revisions are also kept. After running the command, you’ll find the changes as uncommitted local modifications in your working copy.

git reset --soft HEAD~1

Use hard reset:
If you are sure that you don’t want to keep any changes, simply use the reset with –hard flag.

git reset --hard HEAD~1


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.