Cheat Sheets · Git Cheat Sheet · Undo a Pushed Commit — The Safe Way (git revert)

Undo a Pushed Commit — The Safe Way (git revert)

git revert <sha>

Create a new commit undoing exactly that commit

git revert <old>..<new>

Revert a range of commits, oldest first

git revert -m 1 <merge-sha>

Undo a merge commit (1 = keep the branch you merged INTO)

git push

Share the revert like any normal commit — no force needed

Revert patterns

CommandEffect
git revert <sha>Create a new commit undoing exactly that commit
git revert <old>..<new>Revert a range of commits, oldest first
git revert -m 1 <merge-sha>Undo a merge commit (1 = keep the branch you merged INTO)
git pushShare the revert like any normal commit — no force needed

Once a commit is on a shared branch, do not rewrite history — add history. git revert computes the exact opposite of a commit and commits that, so nobody's clone breaks.

Related Git recipes

FAQ

revert vs reset — the decision rule?
Unpushed and private: reset is fine. Pushed or shared: revert, always. Resetting shared branches forces every collaborator to untangle their copies.

Why does reverting a merge need -m 1?
A merge has two parents; Git needs to know which line of history to keep. -m 1 keeps the branch you were on (usually main) and undoes the merged-in side.

What if I revert and then want the change back?
Revert the revert — or cherry-pick the original commit again. History stays additive either way.

Stop memorizing — build it interactively

Generate revert commands in the Git Builder

Full reference: Git Cheat Sheet