Skip to content
Latchkey

git revert: Usage, Options & Common CI Errors

git revert is the safe undo: it records a new commit that reverses an earlier one.

Unlike reset, revert never rewrites history, so it is safe on shared and protected branches.

What it does

git revert applies the inverse of the changes from a commit and records the result as a new commit, leaving the original history untouched.

Common usage

Terminal
git revert <sha>
git revert --no-commit <sha>      # stage the revert, commit later
git revert -m 1 <merge-sha>       # revert a merge, keep mainline 1
git revert --abort

Options

FlagWhat it does
-m <parent>Specify the mainline parent when reverting a merge
--no-commit / -nStage the revert without committing
--continueResume after resolving a conflict
--abortCancel an in-progress revert

Common errors in CI

error: commit <sha> is a merge but no -m option was given - reverting a merge needs a mainline parent. Use git revert -m 1 <merge-sha>. Conflicts during a revert pause it; resolve, git add, then git revert --continue.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →