Re: [PATCH 1/7] [doc] Add new gitmergeconflicts man page
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Sep 30, 2026, 13:19 UTC
- Message-ID
- <ar0MVRV5X8zgZfLy@pks.im>
- In-Reply-To
- <ad4853dc36cdb883c9a8dc6bda747a5ea318e7a8.1790261062.git.gitgitgadget@gmail.com>
On Thu, Sep 24, 2026 at 02:44:16PM +0000, Julia Evans via GitGitGadget wrote:
Show 24 quoted lines
> diff --git a/Documentation/gitmergeconflicts.adoc b/Documentation/gitmergeconflicts.adoc > new file mode 100644 > index 0000000000..612b683e40 > --- /dev/null > +++ b/Documentation/gitmergeconflicts.adoc > @@ -0,0 +1,294 @@ > +gitmergeconflicts(7) > +==================== > + > +NAME > +---- > +gitmergeconflicts - Guide to handling merge conflicts > + > + > +SYNOPSIS > +-------- > +Guide to handling merge conflicts > + > + > +DESCRIPTION > +----------- > + > +Merge conflicts can happen during a `git merge`, `git rebase`, `git > +cherry-pick`, `git pull`, or `git revert`. All of those commands use
Should all of these be using linkgit:, like for example in linkgit:git-merge[1]?
> +the same merge algorithm, and the process for resolving a merge conflict > +is always very similar.
There's also git-am(1), but only when adding the "--3way" flag. So maybe it's best to ignore that command indeed.
Show 8 quoted lines
> +The most common ways to handle a merge conflict are: > + > +* Resolve the conflict. (see <<resolve,HOW TO RESOLVE A MERGE CONFLICT>> > + below for details) > +* Or stop the operation and return your branch to its original state > + with the appropriate `--abort` command, for example `git merge --abort` > + or `git rebase --abort`. See <<git_status,EXAMPLE: GIT STATUS OUTPUT>> below > + for how to find the command to run.
I wonder whether the explanation should be expanded a bit to briefly explain how Git performs a 3-way merge in the first place. I feel like it's quite important to understand what the three different sides of the merge are to make sense of it.
But I may be too far detached from the "normal" user, so this may only cause more confusion for our users.
Show 6 quoted lines
> +[[markers]] > +MERGE CONFLICT MARKERS > +---------------------- > + > +Merge conflicts happen when both of the sides being merged edit the same > +area of a file. When this happens, Git will update the conflicted file
I wonder whether we want to use "hunk" instead of "area". It's jargon again, but I have never heard anybody speak about an "area" before myself.
Show 12 quoted lines
> +to include merge conflict markers `<<<<<<<`, `=======`, and `>>>>>>>`. > +For example, here's a merge conflict where both sides edited a list of > +fruits in different ways: > + > +---- > +FRUITS = [ > + "apple", > +<<<<<<< HEAD > + "cherry", > +======= > + "banana", > +>>>>>>> add-fruit
A bit of a tangent, but sometimes I wonder whether we should make the respective commits a bit easier to access. For example, we could put the equivalent of `git rev-parse --reference <commit>` here for each of the sides.
Show 29 quoted lines
> + "mango", > + "orange", > +] > +---- > + > +The code from one side of the merge conflict is between `<<<<<<<` and > +`=======`, and the code for the other side is between `=======` and > +`>>>>>>>`. See <<ours,"OURS" AND "THEIRS">> below for a full explanation > +of which side is which. > + > + > +[[resolve]] > +HOW TO RESOLVE A MERGE CONFLICT > +------------------------------- > + > +The process for resolving a merge conflict is: > + > +1. Run `git status` to get a list of files with merge conflicts > +2. For each one, find the conflict markers > + (the `<<<<<<<`, `=======`, `>>>>>>>`) and edit the code to > + fix the conflict > +3. Run `git add FILENAME` for each file to mark the conflict as resolved > +4. Run the appropriate `--continue` command to continue the operation > + that was interrupted by the conflict, for example `git merge --continue` > + or `git rebase --continue`. See <<git_status,EXAMPLE: GIT STATUS OUTPUT>> > + below for how to find the command to run. > ++ > +Note: During a `git merge`, `git commit` and `git merge --continue` do > +the the same thing.
s/the the/the/
Maybe we should also say "During a conflicted `git merge`.", but maybe that's redundant.
Show 22 quoted lines
> +[[example]] > +EXAMPLE OF RESOLVING A MERGE CONFLICT > +------------------------------------- > + > +If you see this in your code during a merge conflict: > + > +---- > +FRUITS = [ > + "apple", > +<<<<<<< HEAD > + "cherry", > + "mango", > +======= > + "banana", > + "mango", > +>>>>>>> add-fruit > + "orange", > +] > +---- > + > +Then you might edit that part of the code like this, > +which includes the fruits from both sides of the conflict:
I tend to forget that by default, we only render ours/theirs in the conflict. I always feel like that makes it way harder to resolve conflicts as you don't have the context of what the code looked like originally. So I have diff3 configured locally for ages.
Show 22 quoted lines
> +---- > +FRUITS = [ > + "apple", > + "banana", > + "cherry", > + "mango", > + "orange", > +] > +---- > + > + > +[[tools]] > +TOOLS FOR HANDLING MERGE CONFLICTS > +---------------------------------- > + > +Here are some ways to get extra context while handling a merge conflict: > + > +* There are many graphical "merge tools" for Git, which will normally > + show you the different versions of the code side by side. > + If you have a mergetool configured, `git mergetool` will launch it. > + See also `merge.tool` in linkgit:git-config[1] for a list of > + the mergetools Git supports.
There's also `git merge-tool --tool-help` to list all available drivers.
[snip]
Show 9 quoted lines
> +[[diff3]] > +DIFF3 AND ZDIFF3 > +---------------- > + > +By default, Git doesn't include the original code when formatting > +a merge conflict. To include the original code, you can set the > +configuration option `merge.conflictstyle` to `diff3` or `zdiff3`. > +This extra context can make it much easier to understand what's > +happening in a merge conflict.
Indeed.
[snip]
Show 15 quoted lines
> +[[ours]] > +"OURS" AND "THEIRS" > +------------------- > + > +Git refers to the first part of a merge conflict (between `<<<<<<<` > +and `=======`) as "ours" and the second part (between `=======` and > +`>>>>>>>`) as "theirs". > + > +Normally, "ours" is the commit that was checked out before you started > +the merge, and "theirs" is the other commit. > + > +But when the merge conflict was caused by a `git rebase`, it's the > +opposite: "theirs" is the commit that was checked out before you started > +the merge. This is because under the hood, `git rebase main` checks out > +the `main` commit first before doing the merge operation.
Hmm. This part is a bit confusing to me. "ours" is always the commit that's currently checked out, and "theirs" is always the one that is getting merged into the checked-out commit.
How about a variant of the following instead?
In a conflict, the side between `<<<<<<<` and `=======` is "ours" and the side between `=======` and `>>>>>>>` is "theirs". "Ours" is always the side that `HEAD` points to while the merge happens; "theirs" is the commit being merged into it.
For `git merge <other>`, `HEAD` is your current branch, so "ours" is your branch and "theirs" is `<other>`.
For `git rebase <upstream>`, `HEAD` is first moved to `<upstream>` and your commits are then replayed on top one at a time. So "ours" is the already-rebased history starting at `<upstream>`, and "theirs" is the commit from your original branch that is currently being replayed.
Show 6 quoted lines
> +These terms in Git all mean the same thing when dealing with a merge > +conflict: > + > +* "common ancestor", "base", and "stage 1" > +* "ours", "us", "stage 2", and `HEAD` > +* "theirs", "them", and "stage 3"
I wouldn't say that "stage N" is equivalent to the respective other terms. These stages rather refer to the different versions of a specific file as recorded in the index, they do not indicate a specific commit. In contrast to that, all the other terms may also indicate a specific version of a file, but may also refer to the commits.
Patrick