• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Computing / Undo Git Commit

Undo Git Commit

Last updated on June 8, 2015 by Sal Ferrarello

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.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Filed Under: Computing Tagged With: Git

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in