That is Not What I Meant to Commit
It seems no matter how many times I do git status
, I still managed to sneak in a completely wrong commit sometimes. Additionally, I never remember how to undo a commit so I end up googling “undo git commit” and I get way more information than I need.
My 95% of the Time Solution
There are a lot of answers to this question because there are a lot of scenarios; however, this is almost always my scenario.
- I haven’t pushed my commit (the commit only exists on my local install)
- Only the last commit is wrong
- I want to undo the commit but keep the changes as unstaged
git reset HEAD~1
will reset your last commit and put all of the changes associated with it in an unstaged state
Future Me, you’re welcome
Further Reading
This post How to undo (almost) anything with Git from the GitHub Blog provides solutions to some of the other scenarios where a Git commit needs to be undone.
Leave a Reply