Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+5 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

How can I uncommit my last commit in git?

Is it

git reset --hard HEAD

or

git reset --hard HEAD^

?

1 Answer

+6 votes
by (27.5k points)

Case 1: If all you are looking for is to undo the act of committing, leaving everything else intact, use:

$ git reset --soft HEAD^

Case 2: In case you want to undo the act of committing and everything you'd staged, but leave the work tree (your files intact):

$ git reset HEAD^

Case 3: But if you want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit:

$ git reset --hard HEAD^

git uncommit: How to uncommit my last commit in Git
Intellipaat-community
by (29.3k points)
thanks, it worked for me.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...