Last Updated: September 09, 2019
·
1.79K
· joecritch

Undo 'git commit' without removing files

So, you've made a mistake by committing too early (if that's even possible?). git reset can sound a bit scary, so the least destructive way to undo a commit is the following:

git reset --soft HEAD~1

This does a 'soft reset' (which means it won't delete the files it's about to reset), to the revision that's below the current HEAD revision. (The HEAD revision being the one you want to get rid of.)

2 Responses
Add your response

Great tip, thanks!

over 1 year ago ·

my undo alias:
undo = reset --soft HEAD^

over 1 year ago ·