How to Undo the Last Commit with Git Reset

The aim of this how-to-guide🏁 is to demo the simplest scenarios of undoing in git — scenarios when you have done something and you want to undo it right now. The cleanest use is when the areas are not containing anything else. I use this also for testing scripts or GH actions.

Pavol Kutaj
1 min readApr 24, 2021
  • all of these include variations on git reset HEAD^
  • note: there is a ^ sign — it is different from git reset HEAD !

OTHER VERSIONS OF SIMILAR RESULTS

  • git reset --soft HEAD^ does move a file from commit into index
  • when you git reset --mixed (not with HEAD^) right after that, you unstage that file and put it back into the working area
  • you can achieve the same result (undo the commit → move just commited file back to the working area) just by running git reset --mixed HEAD^ or simply git reset HEAD^
  • you can delete it completely with git reset --hard HEAD^

--

--

Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com