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.
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 withHEAD^
) 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 simplygit reset HEAD^
- you can delete it completely with
git reset --hard HEAD^