Appearance
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 # theirsConflict 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 --abortVerify no markers remain
git diff --checkResolution strategy cheat sheet
| Situation | Approach |
|---|---|
| Lockfile, generated config | checkout --theirs |
| One side is clearly correct | checkout --ours or --theirs |
| Both sides have valid changes | mergetool or manual edit |
| Structural refactor vs feature | Resolve refactor first, commit merge, cherry-pick feature |
| Same conflict across rebase commits | Enable rerere before rebase |
| Don't want to touch current worktree | git 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 -lRelated recipes
- rerere -- automatic reapplication of past resolutions
- merge-strategy -- strategy-level conflict avoidance
- merge-tree -- server-side conflict detection
- merge-driver -- automated resolution for machine files