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.)
Written by Joe Critchley
Related protips
2 Responses
Great tip, thanks!
over 1 year ago
·
my undo alias:
undo = reset --soft HEAD^
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#