Skip to content

How to Fix Git Revert Conflicts

DodaTech 2 min read

In this tutorial, you'll learn about How to Fix Git Revert Conflicts. We cover key concepts, practical examples, and best practices.

The Problem

You run git revert <commit> and get CONFLICT (content): Merge conflict in file.txt. Reverting a commit that touches files modified by subsequent commits creates conflicts. Git doesn't know how to reverse the changes cleanly because the file content has changed since the target commit was made. For example, if commit A changed line 10 of a file, and commit B (made after A) also changed line 10, reverting A creates a conflict because git can't determine which version of line 10 should remain.

Quick Fix

1. Check the conflict status

git status

Files under both modified: have conflicts that need manual resolution.

2. View the conflict

cat file.txt

Conflicting file shows:

<<<<<<< HEAD
Current content that exists now
=======
Content that the revert is trying to restore
>>>>>>> parent of abc1234... (commit message)

3. Resolve the conflict manually

Open the file and edit it to keep the correct content, removing the conflict markers (<<<<<<<, =======, >>>>>>>).

4. Mark the file as resolved

git add file.txt

5. Complete the revert

git revert --continue

Your editor opens for the commit message. Save and close to finish.

6. Abort the revert if needed

git revert --abort

This undoes the revert attempt and returns to the original state.

7. Revert without auto-committing

git revert --no-commit <commit>

The changes are staged but not committed. Fix conflicts, then commit manually:

git add .
git commit -m "Revert commit abc1234"

8. Use a merge strategy to auto-resolve

# Accept the revert's version on conflict
git revert --strategy=recursive --strategy-option=theirs <commit>

# Accept the current version on conflict
git revert --strategy=recursive --strategy-option=ours <commit>

Common Causes

Situation Why Conflict Happens Fix
Reverting an old commit Other commits depend on the reverted code Resolve conflicts manually or use ours/theirs
Reverting a merge commit Complex history, multiple parents Use git revert -m 1 <merge-commit>
File modified since target commit Revert changes conflict with later edits Manual conflict resolution needed
Reverting in wrong order Cascading conflicts Revert oldest commit first

Practice with a Test Repository

cd /tmp
mkdir git-practice && cd git-practice
git init --initial-branch=main
# Initialized empty Git repository in /tmp/git-practice/.git/
echo "test" > file.txt && git add . && git commit -m "init"
# [main (root-commit) abc1234] init

Before running destructive commands on your real repository, practice on a throwaway test repository. This builds confidence and prevents costly mistakes. The reflog is your safety net, but practice makes it less needed.

Prevention

  • Revert commits in chronological order (oldest first) for fewer conflicts
  • Use git revert --no-commit to review changes before committing
  • Check what files the target commit modified: git show --stat <commit>
  • Use git revert --abort to cancel a conflicted revert and reassess your strategy before retrying

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro