How to Undo a Commit in Git (Reset, Revert, or Rebase)
In a hurry? Watch our brief 1-minute vertical video that summarizes the info below.
Git gives you several tools for undoing commits, and the right choice depends on which commit you want to undo and whether the commit has already been pushed to a shared remote. Before reaching for any of them, check whether you just need to edit your last commit β Git's amend feature handles that case cleanly without any of the complexity below. Read more about amend.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Undoing the Last Commit with git reset
When you want to undo your last local commit β one that hasn't been pushed to a remote yet β git reset is the right tool:
$ git reset --soft HEAD~1
This rewinds the branch pointer by one commit. The --soft flag preserves your changes as staged modifications, so you can adjust them and recommit. If you'd prefer to unstage the changes but keep them in your working directory, omit the flag (the default is --mixed):
$ git reset HEAD~1
To discard the changes entirely, use --hard β but note this is permanent and cannot be undone:
$ git reset --hard HEAD~1
Tip
Undoing Commits in Tower
In case you're using the Tower Git client, you can simply hit CMD+Z (or CTRL+Z on Windows) to undo the last commit:
Undoing Multiple Commits
The same reset technique works for returning to any earlier revision β just provide the commit hash instead of HEAD~1:
$ git reset --hard 0ad5a7a6
Keep in mind that reset undoes all commits that came after the one you specify:

If you only want to restore your whole project to a specific earlier state, read more about how to reset to a previous revision.
Undoing a Specific Older Commit with git revert
What if you want to undo the effects of a commit that's not the most recent one β without touching any commits that came after it? That's what git revert is for.
Unlike reset, git revert doesn't delete any commits. It creates a new commit that applies the exact opposite of the changes in the targeted commit:

$ git revert 0ad5a7a6
This makes git revert safe to use on shared branches β it never rewrites history, so your collaborators are not disrupted.
Useful options
--no-commit β stages the reverting changes without immediately creating a commit. Useful if you want to inspect or further modify the changes before committing:
$ git revert a72ef02 --no-commit
--no-edit β skips the commit message prompt and uses Git's default message:
$ git revert a72ef02 --no-edit
Tip
Reverting Commits in Tower
In case you are using the Tower Git client, the revert command is easily available from the right-click menu of any commit:
Deleting a Specific Commit with Interactive Rebase
Need to remove a commit from the middle of your history β one that has unrelated commits after it? Interactive rebase is the tool for this. It's the most powerful option, but also the most disruptive since it rewrites commit history.
$ git rebase -i HEAD~N
Replace N with the number of recent commits you want to inspect. Git opens an editor listing those commits. Change pick to drop next to the commit you want to remove, then save and close:

Because this rewrites history, a force-push is required afterward if the commits are already on a remote. Only use interactive rebase on private branches that haven't been shared with others.
Tip
Interactive Rebase in Tower
In case you are using the Tower Git client, interactive rebase is accessible directly from the right-click menu, and if you make a mistake, you can undo it with CMD+Z:
Learn More
- Check out the chapter Undoing Things in our free online book
- Find the full
git revertreference in the Git documentation
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.