+7 votes
1 view
in DevOps and Agile by (20k 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

+8 votes
by (28.4k 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 (30k points)
thanks, it worked for me.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...