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^

by (29.3k points)
thanks, it worked for me.

Related questions

Browse Categories

...