Interactive: the conflict resolver
Intermediate Core Git
Why this matters
The mechanics of resolving are simple once you have done them twice. The judgement is the part worth practising: given two versions of a sentence, which resolution is actually right? Almost every conflict comes down to four options, and the best answer is frequently the fourth.
The widget
The conflict resolver loads here.
The four resolutions
| Resolution | Choose it when | Risk |
|---|---|---|
| Keep mine | Their change was superseded, or was a mistake you know about | You silently discard work; be sure |
| Keep theirs | Your change was the redundant one, or theirs is clearly better | Same, in the other direction |
| Keep both | The two changes are additions that do not overlap in meaning | Duplicated sentences, or code that says the same thing twice |
| Write something new | Both sides express an intention worth keeping | None, beyond needing a moment's thought |
The last row is the one beginners skip, because the tools present the first three as buttons and the fourth as work. It is usually the correct answer for prose.
The worked example
The conflict from lesson 11.2, with the ancestor visible:
<<<<<<< HEAD
Yes. It is a practice project and costs nothing.
||||||| b6ae751
Yes. It is a practice project for the Git Course and can be used, changed and shared freely.
=======
Yes. It is free for everyone, including commercial use.
>>>>>>> e3e760c6c090dbae77da2af1ffc203d5550dfae5Reading the three versions:
- The original said three things: it is a practice project, it is free, and it may be changed and shared.
- Yours shortened it, keeping "practice project" and "costs nothing", dropping the sharing.
- Theirs kept the freedom, made commercial use explicit, and dropped "practice project".
Now the four options are easy to judge:
| Option | Result | Verdict |
|---|---|---|
| Keep mine | "…a practice project and costs nothing." | Loses the commercial-use clarification Ben added on purpose |
| Keep theirs | "…free for everyone, including commercial use." | Loses nothing important; acceptable |
| Keep both | Two consecutive sentences saying overlapping things | Reads badly |
| Write something new | "Yes. It is free for everyone, including commercial use, and costs nothing." | Keeps both intentions in one sentence |
The last one is what a careful editor would write, and it took ten seconds because the ancestor made both intentions visible.
Judging your own resolution
Before you stage the file, three checks:
- Does it contain every intention? Not every word — every intention. If you dropped one deliberately, that is fine; if you dropped one by accident, this is when to notice.
- Does it read as one thing? Prose that visibly consists of two merged halves usually needs one more pass. Code that defines the same thing twice does not compile.
- Are all the markers gone? Search for
<<<. Every time.
Then, and only then, git add.
Common mistakes
- Clicking "Accept Both" without reading. It is right for independent additions and wrong for two edits of the same sentence.
- Always keeping your own side. Fast, and it quietly reverts colleagues' work.
- Resolving without seeing the ancestor. Turn on
merge.conflictstyle zdiff3once (lesson 11.2) and most decisions become obvious. - Discarding a change you do not understand. Ask; it takes a minute.
Try it yourself
Goal: produce a conflict where each of the four resolutions is plausible, and pick the best.
- In the playground, on
main, make suredocs/faq.md's first answer reads: "Yes. It is a practice project for the Git Course and can be used, changed and shared freely." - On a branch
docs/resolver-practice, change it to "Yes. It is a practice project and costs nothing." Commit. - On
main, change the same line to "Yes. It is free for everyone, including commercial use." Commit. git merge docs/resolver-practice, then open the file and write all four resolutions on paper (or in a scratch file) before choosing.- Resolve with the one you judge best,
git add,git commit --no-edit.
Expected result: you can state, in one sentence each, what "keep mine" and "keep theirs" would lose, and your final text keeps both intentions.
Show solution
Writing the four options out is artificial once, and the point is to make the fourth one a reflex. In real work you will do this in your head in a few seconds, but only if you have practised noticing that the buttons are not the only choices.