Git Reference ยท Concepts
Merge conflict markers
Read Git conflict markers (<<<<<<<, =======, >>>>>>>), understand the diff3 and zdiff3 styles, and resolve, abort or redo a conflicted merge step by step.
A merge conflict happens when both sides changed the same lines (or one side changed a file the other deleted) and Git cannot decide which version to keep. Git stops, writes both versions into the file between conflict markers and waits for you. Nothing is lost: the merge is simply unfinished until you tell Git the result.
<<<<<<< HEAD the line on your branch ======= the line on the branch being merged >>>>>>> feature
Everything between <<<<<<< and ======= is your side ("ours"); everything between ======= and >>>>>>> is the other side ("theirs"). Edit the file so that only the final text remains, delete the three marker lines, then git add the file and finish with git commit (or git merge --continue).
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
| Marker | Meaning |
|---|---|
<<<<<<< HEAD |
start of your side; the label is the current branch or HEAD |
||||||| base |
start of the common ancestor text (only in diff3 and zdiff3 styles) |
======= |
divider between the two sides |
>>>>>>> name |
end of the other side, labelled with the branch or commit being merged |
Style is set with merge.conflictStyle: merge (default, two sides), diff3 (adds the base) and zdiff3 (like diff3 but moves lines both sides share outside the markers, making conflicts smaller).
Usage notes
- Base text helps most. With
diff3you can see what each side changed rather than just two finished versions, which makes resolution much easier. Many people set it globally. - Whole-file shortcuts.
git checkout --ours fileor--theirs filetakes one side entirely. During a rebase the meaning is swapped: "ours" is the branch you are rebasing onto and "theirs" is your own commit being replayed. - Strategy options such as
-X ours/-X theirsresolve only the conflicting hunks automatically, which is easy to misuse; the choice happens silently. - Find what is left.
git diff --name-only --diff-filter=Ulists unmerged files, andgit grep -n '^<<<<<<<'finds forgotten markers. A commit hook can reject them. - Binary and delete/modify conflicts produce no markers: pick a side with
git checkout --ours/--theirs, orgit rm/git addto decide the file's fate. - Start over.
git merge --abortrestores the pre-merge state;git checkout -m filerecreates the markers for one file if you resolved it badly. - Remember resolutions.
rerere.enabledlets Git replay a resolution you made before, useful for repeated rebases. - Tools.
git mergetoolopens your configured visual merge tool.