Lessons · Git · when git will not guess
Resolving a conflict
A conflict happens when both branches changed the same part of the same file. Git marks both versions with <<<<<<<, ======= and >>>>>>> and waits for you to choose.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Conflicts are normal on any team and they are not errors: Git is refusing to guess. Resolving one is editing a file, and finishing is add plus commit.
How to think about it
Open the file, read both versions, keep what is right (one, the other, or a combination), delete the markers, git add the file, commit. git merge --abort if you would rather start over.
Worked example
git switch -c c1 && echo one > c.txt && git add c.txt && git commit -q -m "c1"One version of the file on c1.
git switch main && echo two > c.txt && git add c.txt && git commit -q -m "main"A different version on main.
git merge c1CONFLICT (add/add): both branches wrote c.txt differently.
cat c.txt<<<<<<< HEAD, two, =======, one, >>>>>>> c1: both versions, for you to choose.
echo two > c.txt && git add c.txt && git commit -q -m "Merge c1"Keep what you want, delete the markers, add, commit.
Your turn
Give up on this merge and go back to before it.
git merge
Try it in a real repository
The trap
Committing with the markers still in the file is allowed. Search for <<<<<<< before you add.