Git uncommit: How to uncommit my last commit in Git

1.7K    Asked by AmeliaArnold in Devops , Asked on Jun 15, 2021

 How can I uncommit my last commit in git?

Is it

git reset --hard HEAD

or

git reset --hard HEAD^
?

Answered by Al German

To solve uncommit last commit, there are three cases:


Case 1: If you are seeking 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^


Your Answer

Interviews

Parent Categories