---
topic: software-engineering
author: Crashtech Editorial
published: Sep 12, 2026 · read: 4 min
---

Why Does Git Revert Cause Conflicts: How Inverse Commits Collide with Subsequent Diffs

Why git revert is not a magic eraser: three-way merge math, colliding subsequent commits, and the proper procedure for clean conflict resolution.

– –

When a software deployment introduces a critical production bug, an engineering lead reaches for the safest, most responsible command in the Git manual:

git revert <commit-hash>

Unlike git reset --hard (which destructively rewrites history and causes chaos on shared collaborative branches), git revert is designed to be safe: it records an append-only commit that applies the exact inverse patch of the broken change, keeping history intact.

And yet, at the worst possible moment (during a high-severity production outage), Git suddenly stops and throws an alarming error:

error: could not revert 4a8b19f... Add checkout discount logic
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git revert --continue'
CONFLICT (content): Merge conflict in src/checkout.ts

Why does undoing a commit cause a conflict? How can removing code that was already committed collide with itself?

To resolve this without corrupting production code, you must understand the mathematical reality of Git: git revert is not an eraser; it is a three-way merge in reverse.

+--------------------------------------------------------------------------+
|                  THE REVERT COMMIT COLLISION GRAPH                       |
|                                                                          |
|  [Commit C1: Base Line]                                                  |
|        |                                                                 |
|        v                                                                 |
|  [Commit C2: Introduced Buggy Feature]  <--- YOU WANT TO REVERT THIS!    |
|        |                                                                 |
|        v                                                                 |
|  [Commit C3: Edited Same File / Refactored Function]                     |
|        |                                                                 |
|        v                                                                 |
|  [Revert C2]: Git compares C2's parent (C1) against Head (C3).           |
|               C3 modified the exact lines C2 wants to delete!            |
|               RESULT: Three-way merge conflict!                          |
+--------------------------------------------------------------------------+

The Mathematical Mechanism: Three-Way Merge

Engineers often imagine that git revert C2 simply searches for the lines added in commit $C_2$ and deletes them.

Git does not work that way. Git never operates on isolated commits in a vacuum. Under the hood, Git performs a Three-Way Merge using three references:

  1. The Merge Base ($B$): Commit $C_2$ (the commit being reverted).
  2. The “Theirs” Tree ($T$): Commit $C_1$ (the parent of $C_2$, representing what code looked like before the bug).
  3. The “Ours” Tree ($O$): Commit $C_3$ (the current HEAD of the branch, representing what code looks like right now).

Git attempts to apply the diff between $C_2$ and $C_1$ onto $C_3$:

Revert Diff = Diff(C2 -> C1)

If any commit between $C_2$ and HEAD ($C_3$) modified, formatted, or touched the exact same lines of code that $C_2$ introduced, Git faces an irreconcilable ambiguity:

  • Commit $C_1$ says: “This line should not exist.”
  • Commit $C_3$ says: “This line should contain const discount = apply_promo(cart);.”

Git cannot mathematically guess your intent: did you want to delete the line, or did you want to keep the new modification introduced by $C_3$?

Because Git prioritizes safety above all else, it halts and demands human resolution.

Concrete Conflict Example

Trace a real file across three commits:

Commit C1 (Initial State)

function checkout(cart: Cart) {
  const total = calculateTotal(cart);
  return processPayment(total);
}

Commit C2 (The Bad Commit: Adds Tax Calculation)

function checkout(cart: Cart) {
  const total = calculateTotal(cart);
  const tax = total * 0.08; // Added in C2
  return processPayment(total + tax);
}

Commit C3 (Subsequent Commit: Refactors Currency Formatting)

function checkout(cart: Cart) {
  const total = calculateTotal(cart);
  const tax = formatCurrency(total * 0.08); // Modified in C3!
  return processPayment(total + tax);
}

Now, the team discovers that the tax calculation in $C_2$ caused a rounding bug and runs git revert C2.

Git looks at line 3:

  • In $C_2$, line 3 was const tax = total * 0.08;.
  • To revert, Git wants to replace that line with what existed in $C_1$ (which was nothing).
  • But in the current working tree ($C_3$), line 3 has become const tax = formatCurrency(total * 0.08);.

Git emits the conflict marker:

<<<<<<< HEAD
  const tax = formatCurrency(total * 0.08);
=======
>>>>>>> parent of c2... Add tax calculation

The Step-by-Step Resolution Protocol

When a production revert triggers a conflict, follow this exact four-step protocol:

[1. Identify Conflicted Files]  : Run `git status`
[2. Edit and Resolve Markers]   : Keep C3's legitimate edits while removing C2's bug
[3. Stage the Clean Files]      : Run `git add <resolved-files>`
[4. Finalize the Revert]        : Run `git revert --continue`

Step 1: Inspect the Status

git status
# Shows: Unmerged paths: (both modified) src/checkout.ts

Step 2: Open the File and Resolve Markers

Do not blindly delete either side of the conflict. Understand the dependency:

  • If commit $C_3$ fundamentally relied on the buggy feature, you must either refactor $C_3$ or revert both $C_3$ and $C_2$ in reverse order:
git revert C3
git revert C2
  • If $C_3$‘s changes can survive without $C_2$, edit the file manually to remove the tax logic while preserving any unrelated formatting.

Step 3: Stage the Resolved File

git add src/checkout.ts

Note: Do not run git commit! Running git commit creates a standard commit and leaves the revert operation in a dangling, unfinished state.

Step 4: Continue the Revert

git revert --continue

Git opens your configured text editor with an automatically generated revert message:

Revert "Add tax calculation"

This reverts commit 4a8b19f3...
Conflicts:
    src/checkout.ts

Save and exit. The clean revert commit is permanently recorded in Git history.

Reverting a Merge Commit (-m 1)

Another common error occurs when attempting to revert a pull request merge commit:

git revert -m 1 <merge-commit-hash>

A merge commit has two parents:

  • Parent 1 (-m 1): The mainline branch (main) you merged into.
  • Parent 2 (-m 2): The feature branch that was merged.

Passing -m 1 tells Git to revert the changes relative to the mainline branch.

The Trap: If you later fix the feature branch and try to merge it back into main, Git will ignore all the original commits because Git’s history records that those commit IDs were already merged and reverted. You must explicitly revert the revert commit before re-merging the feature branch.

Git revert conflicts are not flaws in version control; they are mathematical warnings that your codebase’s history has become intertwined. By understanding the three-way merge base, you resolve conflicts with confidence.

Advertisement

/* Comments */