git revert is the safe way to undo a commit that has already been pushed. Instead of rewriting history like git reset, it creates a new commit that reverses the changes — so the undo itself becomes part of the record.
The Problem
You pushed a commit that broke the build — or a feature got cancelled and its commit needs to be undone from main. You know git reset --hard would work locally, but that commit is already on a shared branch and rewriting history would destroy your teammates' work.
git revert is the safe undo for shared branches. Instead of deleting history, it creates a new commit that reverses the changes of the target commit. The original commit stays in the log, and the undo itself becomes a traceable record. This is the correct approach whenever you need to undo something that has already been pushed.
Common mistakes developers make with this:
Using git reset --hard on a shared branch instead of git revert — this rewrites history and forces a destructive push
Thinking git revert deletes the original commit — it does not, it adds a new one on top
Reverting a merge commit without the -m 1 flag and getting an error
Not running git log first to confirm the exact commit SHA to revert
Gitoryx: In Gitoryx, you can right-click any commit in the commit graph and select 'Revert commit' — no SHA to copy, no flags to memorize. The revert commit is created and staged in one click.
What is Revert: How to Safely Undo a Pushed Commit?
git revert <commit> creates a new commit that applies the inverse of the changes in the specified commit. The original commit is never modified or removed — making revert safe to use on any branch, including shared and public ones. It is the correct alternative to git reset when a commit has already been pushed.
Step-by-Step Guide
1
Find the commit SHA to revert
Before reverting, run git log --oneline to identify the exact commit you want to undo. Copy the short SHA of that commit.
bash
git log --oneline
# a3f2c1d (HEAD -> main) add broken feature
# 9b1e4fa add login form validation
# 7c0d2ae init project structure
# → We want to revert a3f2c1d
Double-check with git show <sha> before reverting to confirm it contains exactly what you expect to undo.
2
Revert a single commit
Pass the commit SHA to git revert. Git creates a new commit that reverses all changes from the target commit and opens your editor to confirm the commit message.
bash
git revert a3f2c1d
# Git opens your editor with a default message:
# Revert "add broken feature"
#
# This reverts commit a3f2c1d4e5b6...
#
# Save and close to create the revert commit.
3
Revert without opening an editor
Use --no-edit to skip the editor and accept the default revert message automatically. Useful in scripts or CI workflows.
bash
git revert --no-edit a3f2c1d
4
Stage the revert without committing (-n flag)
The -n (or --no-commit) flag applies the inverse changes to your staging area without creating a commit. This lets you review or modify the revert before finalizing it.
bash
git revert -n a3f2c1d
# Inspect the staged changes
git diff --staged
# Then commit when ready
git commit -m "revert broken feature"
Use -n when you want to combine the revert with additional fixes into a single commit.
See this workflow in Gitoryx. Right-click any commit in the Gitoryx graph and choose 'Revert commit' — no SHA to copy or flags to remember
If the revert conflicts with later changes (because the reverted code was modified after it was introduced), Git pauses and reports a conflict. Resolve it the same way as a merge conflict.
bash
git revert a3f2c1d
# If a conflict occurs:
# CONFLICT (content): Merge conflict in src/app.ts
# error: could not revert a3f2c1d
# 1. Open the conflicted file and resolve markers
# 2. Stage the resolved file
git add src/app.ts
# 3. Complete the revert
git revert --continue
To abort the revert entirely and return to the state before you started, run git revert --abort.
6
Revert a merge commit
Reverting a merge commit requires the -m flag to specify which parent to revert to. Parent 1 (-m 1) is almost always what you want — it reverts to the branch the merge was made into.
Reverting a merge commit undoes the merge itself, but does not remove the individual commits from the merged branch. If you later want to re-merge that branch, Git will not see those commits as new.
Common Mistakes to Avoid
Using git reset instead of git revert on a shared branch
git reset --hard moves the branch pointer backwards and rewrites history. If teammates have already pulled those commits, their local history diverges and the only fix is a destructive force-push.
Fix: Use git revert on any branch that has been pushed. Reserve git reset for local-only commits that have never left your machine.
Reverting a merge commit without -m 1
Merge commits have two parents. Git doesn't know which parent to revert to without the -m flag, and throws: 'error: commit is a merge but no -m option was given'.
Fix: Always use git revert -m 1 <merge-sha> when reverting a merge commit. Parent 1 is the branch the merge was made into (typically main or develop).
Not reviewing the revert diff before pushing
A revert may produce unexpected results if later commits modified the same code. Pushing without reviewing can introduce regressions.
Fix: After reverting, run git show HEAD to verify the revert commit contains exactly what you expect before pushing.
Gitoryx — macOS & Windows
Revert any commit in one click with Gitoryx
Right-click any commit in the Gitoryx graph and choose 'Revert commit' — no SHA to copy or flags to remember
The revert commit appears immediately in the visual graph so you can verify the result before pushing
Conflicts during revert are surfaced in the same visual conflict editor used for merges
Gitoryx distinguishes between revert and reset in its UI, preventing the most common mistake
What is the difference between git revert and git reset?
git revert creates a new commit that undoes a previous commit's changes — history is preserved. git reset moves the branch pointer backwards and removes commits from history. Use git revert for pushed commits on shared branches, and git reset only for local commits that have not been pushed.
Does git revert delete the original commit?
No. git revert never deletes any commit. It creates a new commit that applies the inverse changes. The original commit remains in the log permanently. This is exactly what makes it safe to use on shared branches.
What does git revert -n do?
git revert -n (or --no-commit) applies the reverting changes to your staging area without automatically creating a commit. This lets you review, modify, or combine the revert with other changes before committing manually.
How do I revert multiple commits?
You can list multiple SHAs: git revert <sha1> <sha2> <sha3>. Or revert a range: git revert HEAD~3..HEAD to revert the last 3 commits. Each produces a separate revert commit unless you use -n to batch them into one.
What should I do if git revert causes a conflict?
Resolve the conflict in the affected file (remove the <<<<<<<, =======, >>>>>>> markers), stage it with git add, then run git revert --continue. To abort entirely and return to where you started, use git revert --abort.
Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS and Windows, and built for developers who want to move fast without breaking things.