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 --abortOptions
| Flag | What it does |
|---|---|
| -m <parent> | Specify the mainline parent when reverting a merge |
| --no-commit / -n | Stage the revert without committing |
| --continue | Resume after resolving a conflict |
| --abort | Cancel 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
git reset: Usage, Options & Common CI Errorsgit reset moves HEAD and optionally the index and working tree. Reference for --soft, --mixed, --hard, and ho…
git cherry-pick: Usage, Options & Common CI Errorsgit cherry-pick applies the changes from specific commits onto the current branch. Reference for -x, -n, rang…
git merge: Usage, Options & Common CI Errorsgit merge joins two branch histories into one. Reference for --no-ff, --squash, --abort, and how to detect an…
git log: Usage, Options & Common CI Errorsgit log shows commit history with flexible formatting. Reference for --oneline, --graph, --pretty, ranges, an…