Skip to content

Merge conflict resolution ​

Pre-resolution checks ​

# Conflicted files
git status --short | grep ^UU

# What changed on each side
git diff --ours conflicted-file.txt
git diff --theirs conflicted-file.txt
git diff --base conflicted-file.txt

# Stage SHAs for all three versions
git ls-files --unmerged

# Extract a specific stage
git checkout --stage=1 -- conflicted-file.txt   # ancestor
git checkout --stage=2 -- conflicted-file.txt   # ours
git checkout --stage=3 -- conflicted-file.txt   # theirs

Conflict marker reference (zdiff3) ​

<<<<<<< HEAD         # ours (branch you are merging INTO)
||||||| abc1234      # ancestor (common base)
=======              # separator
>>>>>>> feature/x    # theirs (branch you are merging FROM)

Set globally: git config --global merge.conflictstyle zdiff3

Quick resolution paths ​

# Take one side wholesale
git checkout --ours -- file.txt && git add file.txt
git checkout --theirs -- file.txt && git add file.txt

# Launch 3-pane mergetool
git mergetool

# Delete file (modify/delete or rename/delete)
git rm file.txt

# Abort the entire merge
git merge --abort

# Abort the entire rebase
git rebase --abort

Verify no markers remain ​

git diff --check

Resolution strategy cheat sheet ​

SituationApproach
Lockfile, generated configcheckout --theirs
One side is clearly correctcheckout --ours or --theirs
Both sides have valid changesmergetool or manual edit
Structural refactor vs featureResolve refactor first, commit merge, cherry-pick feature
Same conflict across rebase commitsEnable rerere before rebase
Don't want to touch current worktreegit worktree add ../resolve main

CI detection ​

# Check mergeability without checkout (git merge-tree)
git merge-tree --write-tree --name-only HEAD feature/branch
echo $?   # 0 = no conflicts, non-zero = conflicts

# Count conflicted files
git diff --name-only --diff-filter=U | wc -l

Git Master — Git Reference for Every Skill Level