Hone

Lessons · Git · reading a conflict

Reading a conflict

Between <<<<<<< and ======= is where you are. Between ======= and >>>>>>> is what is arriving. The label after >>>>>>> names it.

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

During a MERGE 'where you are' is your branch. During a REBASE it is the branch you are rebasing onto, and your own commit is the bottom half. That inversion is the commonest way a rebase conflict gets resolved backwards.

How to think about it

Read the labels rather than assuming. Git writes them for exactly this reason, and they are different in the two cases.

Worked example

git rebase main
It stops. One commit could not be applied cleanly.
cat f.txt
The top half says 'the upstream' -- which is MAIN, not your work.
git status --short
UU: unmerged, changed on both sides.
git show :2:f.txt
Stage 2, what git calls ours: the upstream, during a rebase.
git show :3:f.txt
Stage 3, theirs: your own commit. This is the inversion.
git rebase --abort
And out, with nothing changed.

Your turn

Show the version of the file from the side being applied.

git show :f.txt

The trap

Reaching for --ours during a rebase because you want to keep your work. Ours is the upstream there, and your work is theirs.

Practise reading a conflict on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.