How to Undo a Commit in Git (Reset, Revert, or Rebase)
Short answer
To undo the last local commit (one that hasn't been pushed yet) while keeping your changes staged, run git reset --soft HEAD~1. To unstage the changes but keep the edits in your working directory, use git reset --mixed HEAD~1. To discard the changes entirely, use git reset --hard HEAD~1 β this permanently deletes the uncommitted work. To undo a specific older commit without altering history, use git revert <commit-hash>, which creates a new commit that applies the reverse of the targeted commit's changes; this is the safest approach for shared branches. The --no-commit flag stages the reverting changes without immediately committing them, and --no-edit skips the commit message prompt. For commits already pushed to a shared remote, always prefer git revert over reset to avoid rewriting public history. To delete a specific commit in the middle of your history, use interactive rebase: run git rebase -i HEAD~N, then change pick to drop next to the target commit. History-rewriting commands (reset --hard, rebase with drop) require a force-push if already shared and should only be used on private branches.
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!
Free. We email you a ZIP with our cheat sheets.
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:
Careful: this command can discard work.
git reset --hard HEAD~1
No Command Line Needed
Undoing Commits in Tower
In case you're using the Tower Git client, you can simply hit CMDZ (or CTRLZ 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:
Careful: this command can discard work.
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
No Command Line Needed
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.
No Command Line Needed
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 CMDZ:
Learn More
- Check out the chapter Undoing Things β Command Line edition in our free online book
- Find the full
git revertreference in the Git documentation