# git revert: Usage, Options & Common CI Errors

> git revert undoes a commit by creating a new inverse commit, keeping history intact. Reference for -m, --no-commit, --continue, and merge-revert errors.

Source: https://latchkey.dev/learn/command-reference/git-revert  
Updated: 2026-06-25

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

| 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.

## Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

```.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### git revert: Usage, Options & Common CI Errors?

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 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
