Thread View: linux.kernel.git
12 messages
12 total messages
Started by "Julia Evans via GitGitGadget"
Mon, 12 Oct 2026 14:53
[PATCH v3 0/6] [doc] Add new page on merge conflicts
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
332 lines
22497 bytes
22497 bytes
Handling merge conflicts is difficult, and currently Git's guidance on merge
conflicts isn't giving users the information they need to navigate the
process. As usual, the process I used to write this was to collect comments
from Git users on the existing documentation, and then address those issues.
I listed the specific issues we're aiming to solve in the first commit
message in the series.
This patch series introduces a new manual page, gitmergeconflicts, which
explains the process of explaining a merge conflict with examples. It also
links to that new page from the commands which can cause merge conflicts,
instead of trying to reexplain the process every time.
Changed in v2:
* Explain what a merge conflict is (thanks to Junio & Ben)
* rewrite the "ours" vs "theirs" section (thanks to Patrick for the
comments)
* add git log --merge (thanks to Ben)
* Leave most of the content of git cherry-pick as-is, to make this patch
set smaller (thanks to Junio)
* remove the SYNOPSIS since hopefully that won't be required anymore by the
time this is merged
* Fix a typo in git revert (s/reverted conflict/reverted commit/)
* 's/the the/the/' (thanks to Patrick)
* s/[doc] Thing/doc: thing/ in commit messages (thanks to Tuomas)'
* squash the commit fixing the linter error (thanks to Junio)
* list reviewers in Reviewed-by
Changed in v3:
Thanks to all the comments from Junio.
* Add signoff from Marie
* In "For example, here's a merge conflict where both sides edited a list
of", add a little more detail about how to interpret the merge conflict
* When we introduce a merge mention "semantic merge conflicts"
* Say "... and any other command that does a merge" when listing commands
that can cause merge conflicts.
* Reviewed-by is not the right thing, use Helped-by
* Adjust phrasing in git revert and git cherry-pick man pages
* Reference the "ours" section in "git show :2:filename shows the "ours""
* "there's one file left with conflicts in it: fruits.py" isn't precise
enough, instead say "the conflicts in fruits.py haven't been marked as
resolved"
* Delete the explanation of zdiff3 and add a brief warning instead. Don't
be too prescriptive, we should tell people what the issue is (ambiguity)
instead of trying to impose our opinion.
* Explain ||||||| when we add diff3
* Fix example in "EXAMPLE OF RESOLVING A MERGE CONFLICT" to make it
consistent with the other examples
* Replace "configuration option" with "configuration variable"
* Mention --skip instead of saying "the most common ways", which is
ambiguous
* Add a pointer to the extended AUTO_MERGE sentence
some non-changes in v3:
* didn't add any extra Reviewed-by
* "return your branch to its original state": left the same because during
a multistep cherry-pick the branch does need to be returned to its
original state
* leave the explanation of AUTO_MERGE the same since Marie says it's more
clear this way
* leave contractions alone for now
* don't say semantic merge applies to all merges since I think that will be
clear to readers
* the wording of "When Git merges two commits together" is a bit weird but
we don't have a better idea right now
* don't explain --left-right. Can be very easily added in the future if we
think it's important.
Thanks to Lobo, Adam Svahn, Louis Vanier, David Turner, Ben Zanin, Salih,
and about 12 others who gave feedback on both the original git merge man
page, as well as the proposed improvements.
Julia Evans (6):
doc: add new gitmergeconflicts man page
doc: git-merge: link to new merge conflicts guide
doc: git-rebase: link to new merge conflicts guide
doc: git-revert: link to new merge conflicts guide
doc: git-cherry-pick: link to new merge conflicts guide
doc: git-pull: link to new merge conflicts guide
.gitattributes | 1 +
Documentation/Makefile | 1 +
Documentation/git-cherry-pick.adoc | 8 +-
Documentation/git-merge.adoc | 125 +---------
Documentation/git-pull.adoc | 3 +-
Documentation/git-rebase.adoc | 13 +-
Documentation/git-revert.adoc | 5 +
Documentation/gitmergeconflicts.adoc | 330 +++++++++++++++++++++++++++
Documentation/meson.build | 1 +
command-list.txt | 1 +
10 files changed, 357 insertions(+), 131 deletions(-)
create mode 100644 Documentation/gitmergeconflicts.adoc
base-commit: 3bc0341126508f78f5869cbfc0005e987efdf0c7
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2237%2Fjvns%2Fmerge-conflicts-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2237/jvns/merge-conflicts-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/2237
Range-diff vs v2:
1: ab0344f947 ! 1: 7aa0ae7ec3 doc: add new gitmergeconflicts man page
@@ Commit message
place, since it's a really nice example of a place Git has a consistent
interface between similar commands.
+ Only discuss merge, rebase, cherry-pick, and revert for now even though
+ there are other ways that merge conflicts can happen because it's
+ awkward to talk about `am`, `apply`, and `checkout -m`.
+
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
- Reviewed-by: D. Ben Knoble <ben.knoble+github@gmail.com>
- Reviewed-by: Patrick Steinhardt <ps@pks.im>
+ Helped-by: D. Ben Knoble <ben.knoble+github@gmail.com>
+ Helped-by: Patrick Steinhardt <ps@pks.im>
+ Signed-off-by: Julia Evans <julia@jvns.ca>
+ Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
## .gitattributes ##
@@ Documentation/gitmergeconflicts.adoc (new)
+-----------
+
+Merge conflicts can happen during a `git merge`, `git rebase`, `git
-+cherry-pick`, `git pull`, or `git revert`. All of those commands use
-+the same merge algorithm, and the process for resolving a merge conflict
-+is always very similar.
++cherry-pick`, `git pull`, `git revert`, or any other command that does
++a merge. All of those commands use the same merge algorithm, and the
++process for resolving a merge conflict is always very similar.
+
-+The most common ways to handle a merge conflict are:
++There are 3 ways to handle a merge conflict:
+
+* 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
++* 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.
++* Or (if you're in a multi-step rebase or cherry-pick) skip the problematic
++ commit with the appropriate `--skip` command
+
+WHAT IS A MERGE CONFLICT?
+-------------------------
@@ Documentation/gitmergeconflicts.adoc (new)
+ sides' edits in the file, and leaves <<markers, merge conflict markers>>
+ that you need to resolve.
+
++[NOTE]
++================================
++Even if Git successfully merges both sides with no conflicts, it's
++possible to end up with code that doesn't work. For example, this can
++happen if one side renames a function, and the other side adds a call to
++the old function. This is called a "semantic merge conflict".
++================================
++
+[[markers]]
+MERGE CONFLICT MARKERS
+----------------------
@@ Documentation/gitmergeconflicts.adoc (new)
+When there's a merge conflict, Git will update the conflicted file
+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 in different ways -- one side added "cherry" and the other side
++added "banana":
+
+----
+FRUITS = [
@@ Documentation/gitmergeconflicts.adoc (new)
+ "apple",
+<<<<<<< HEAD
+ "cherry",
-+ "mango",
+=======
+ "banana",
-+ "mango",
+>>>>>>> add-fruit
++ "mango",
+ "orange",
+]
+----
@@ Documentation/gitmergeconflicts.adoc (new)
+ See also `merge.tool` in linkgit:git-config[1] for a list of
+ the mergetools Git supports.
+
-+* You can set the configuration option `merge.conflictstyle=diff3`.
-+ See <<diff3,DIFF3 AND ZDIFF3>> below for more.
++* You can set the configuration variable `merge.conflictstyle=diff3`.
++ See <<diff3,DIFF3>> below for more.
+
+* `git log --merge -p <filename>` will list all commits which
+ caused the merge conflict for `<filename>`, and the diff
@@ Documentation/gitmergeconflicts.adoc (new)
+* Look at the original files. `git show :1:filename` shows the
+ common ancestor, `git show :2:filename` shows the "ours"
+ version, and `git show :3:filename` shows the "theirs"
-+ version.
++ version. See <<ours,"OURS" AND "THEIRS">> below for more on
++ "ours" and "theirs".
+
+Here are some ways to track your progress while handling a conflict:
+
@@ Documentation/gitmergeconflicts.adoc (new)
+
+* Use `git diff AUTO_MERGE` to show what changes you've made so far to
+ resolve the conflicts.
++ See <<automerge,EXAMPLE OF USING `AUTO_MERGE`>> below for more.
+
+[[git_status]]
+EXAMPLE: GIT STATUS OUTPUT
@@ Documentation/gitmergeconflicts.adoc (new)
+ original state
+* you should run `git rebase --continue` when you're done resolving all
+ the conflicts
-+* there's one file left with conflicts in it: `fruits.py`
++* the conflicts in `fruits.py` haven't been marked as resolved
+
+----
+$ git status
@@ Documentation/gitmergeconflicts.adoc (new)
+
+
+[[diff3]]
-+DIFF3 AND ZDIFF3
-+----------------
++DIFF3
++-----
+
+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`.
++configuration option `merge.conflictstyle` to `diff3`.
+This extra context can make it much easier to understand what's
+happening in a merge conflict.
+
+Here's an example of what a merge conflict would look like when using
-+`diff3`. It shows, in order, the "ours" side of the conflict, the
-+original code (`"mangoooo"`), and the "theirs" side of the
-+conflict. With this view, you can see that both sides fixed the spelling
++`diff3`. There's an extra section (between `|||||||` and `=======`)
++with the original code.
++
++With this view, you can see that both sides fixed a spelling
+mistake in "mango", and each added one fruit to the list.
+
+----
@@ Documentation/gitmergeconflicts.adoc (new)
+]
+----
+
-+Here's the same example using `zdiff3`. `zdiff3` takes lines that are
-+shared between both sides (the `"mango"` line) and moves them outside
-+the conflicted area. This makes the conflicted area shorter, but the
-+downside is that it's impossible to tell if `"mango"` was part of the
-+original list of fruits or not.
-+
-+----
-+FRUITS = [
-+ "apple",
-+<<<<<<< HEAD
-+ "cherry",
-+||||||| 1c22e48
-+ "mangoooo",
-+=======
-+ "banana",
-+>>>>>>> add-fruit
-+ "mango",
-+ "orange",
-+]
-+----
-+
++[NOTE]
++================================
++`zdiff3` is an alternative to `diff3` that makes the merge conflict
++shorter by making it more ambiguous.
++================================
+
+[[ours]]
+"OURS" AND "THEIRS"
2: d5241eb901 = 2: 8bdbd64ca3 doc: git-merge: link to new merge conflicts guide
3: 72b1207045 = 3: 34ba85fcad doc: git-rebase: link to new merge conflicts guide
4: cfa0a8254a ! 4: 85e117b070 doc: git-revert: link to new merge conflicts guide
@@ Documentation/git-revert.adoc: both will discard uncommitted changes in your wor
See "Reset, restore and revert" in linkgit:git[1] for the differences
between the three commands.
-+If there have been new commits since the reverted commit, there may
-+be a merge conflict. See linkgit:gitmergeconflicts[7]
-+(or `git help mergeconflicts`) for a guide to handling merge conflicts.
++Reverting a commit may result in a merge conflict.
++See linkgit:gitmergeconflicts[7] (or `git help mergeconflicts`)
++for a guide to handling merge conflicts.
+
OPTIONS
-------
5: 62b70e9a02 ! 5: f99c99f955 doc: git-cherry-pick: link to new merge conflicts guide
@@ Documentation/git-cherry-pick.adoc: Given one or more existing commits, apply th
-When it is not obvious how to apply a change, the following
-happens:
-+When it is not obvious how to apply a change, there may
-+be a merge conflict. See linkgit:gitmergeconflicts[7]
-+(or `git help mergeconflicts`) for a guide to handling merge conflicts.
-+
+When a merge conflict happens:
1. The current branch and `HEAD` pointer stay at the last commit
@@ Documentation/git-cherry-pick.adoc: happens:
-See linkgit:git-merge[1] for some hints on resolving such
-conflicts.
--
++See linkgit:gitmergeconflicts[7] (or `git help mergeconflicts`)
++for a guide to handling merge conflicts.
+
OPTIONS
-------
- <commit>...::
@@ Documentation/git-cherry-pick.adoc: $ git cherry-pick -Xpatience topic^ <4>
SEE ALSO
--------
6: ac77db6762 = 6: 7831b77178 doc: git-pull: link to new merge conflicts guide
--
gitgitgadget
[PATCH v3 1/6] doc: add new gitmergeconflicts man page
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
437 lines
23096 bytes
23096 bytes
From: Julia Evans <julia@jvns.ca>
Introduce a new page, `gitmergeconflicts`, that explains the process of
handling a merge conflict in a way that addresses the following issues,
which came from feedback from Git users on the current explanation of
merge conflicts in the `git merge` man page:
- The process for resolving a merge conflict is only explained in the
`git merge` man page, even though there are several other commands
which can result in conflicts
- Sometimes we use "ours" and "theirs" to refer to the two sides of
the merge conflicts and sometimes we use HEAD and MERGE_HEAD. It should
be consistent. Also the terms "ours" and "theirs" are not explained.
Similarly, it says "The part before the `=======` is typically your
side...", but doesn't explain what "typically" means.
- It introduces the merge format using an analogy to RCS, which very few
Git users have ever used
- In "The only clean-ups you need are to reset the index file to the
`HEAD` commit to reverse 2. and to clean up working tree changes made
by 2. and 3.", it's not clear to users what "2" and "3" are supposed
to mean
- It uses a cultural reference ("Conflict resolution is hard; let's go
shopping.") which is confusing or unfamiliar to some people. I think it
would be clearer for users to use a code example instead.
- It doesn't explain the difference between diff3 and zdiff3
- It sometimes uses the term "area" and sometimes uses the term "hunk"
Also document the unified `--abort`, `--continue` workflow in one
place, since it's a really nice example of a place Git has a consistent
interface between similar commands.
Only discuss merge, rebase, cherry-pick, and revert for now even though
there are other ways that merge conflicts can happen because it's
awkward to talk about `am`, `apply`, and `checkout -m`.
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Helped-by: D. Ben Knoble <ben.knoble+github@gmail.com>
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Julia Evans <julia@jvns.ca>
Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
---
.gitattributes | 1 +
Documentation/Makefile | 1 +
Documentation/gitmergeconflicts.adoc | 330 +++++++++++++++++++++++++++
Documentation/meson.build | 1 +
command-list.txt | 1 +
5 files changed, 334 insertions(+)
create mode 100644 Documentation/gitmergeconflicts.adoc
diff --git a/.gitattributes b/.gitattributes
index 26490ad60a..0a0fc950b1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -14,6 +14,7 @@ CODE_OF_CONDUCT.md -whitespace
/t/oid-info/* text eol=lf
/Documentation/git-merge.adoc conflict-marker-size=32
/Documentation/git-merge-file.adoc conflict-marker-size=32
+/Documentation/gitmergeconflicts.adoc conflict-marker-size=32
/Documentation/gitk.adoc conflict-marker-size=32
/Documentation/user-manual.adoc conflict-marker-size=32
/t/t????-*.sh conflict-marker-size=32
diff --git a/Documentation/Makefile b/Documentation/Makefile
index f8dea4b395..bc49641dda 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -58,6 +58,7 @@ MAN7_TXT += gitdiffcore.adoc
MAN7_TXT += giteveryday.adoc
MAN7_TXT += gitfaq.adoc
MAN7_TXT += gitglossary.adoc
+MAN7_TXT += gitmergeconflicts.adoc
MAN7_TXT += gitpacking.adoc
MAN7_TXT += gitnamespaces.adoc
MAN7_TXT += gitremote-helpers.adoc
diff --git a/Documentation/gitmergeconflicts.adoc b/Documentation/gitmergeconflicts.adoc
new file mode 100644
index 0000000000..3c6eaaddf8
--- /dev/null
+++ b/Documentation/gitmergeconflicts.adoc
@@ -0,0 +1,330 @@
+gitmergeconflicts(7)
+====================
+
+NAME
+----
+gitmergeconflicts - Guide to handling merge conflicts
+
+DESCRIPTION
+-----------
+
+Merge conflicts can happen during a `git merge`, `git rebase`, `git
+cherry-pick`, `git pull`, `git revert`, or any other command that does
+a merge. All of those commands use the same merge algorithm, and the
+process for resolving a merge conflict is always very similar.
+
+There are 3 ways to handle a merge conflict:
+
+* Resolve the conflict. (see <<resolve,HOW TO RESOLVE A MERGE CONFLICT>>
+ below for details)
+* 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.
+* Or (if you're in a multi-step rebase or cherry-pick) skip the problematic
+ commit with the appropriate `--skip` command
+
+WHAT IS A MERGE CONFLICT?
+-------------------------
+
+When Git merges two commits together, it looks at the changes that
+each side has made and combines those changes. For example, if one side
+edited lines 1-5 of `hello.py` and the other side edited lines 20-25 of
+the same file, then it can easily combine them since there's no overlap.
+
+But if both sides edited overlapping lines of the same file (for example
+one side edited lines 1-5 and the other edited lines 3-6), Git will
+not try to guess how to combine those changes. This is called a "merge
+conflict".
+
+When this happens, Git shows you both sides' edits and asks you to pick
+how to resolve them. It:
+
+* Stages all of the files which were successfully merged
+* For the files with conflicts, it marks them as conflicted, puts both
+ sides' edits in the file, and leaves <<markers, merge conflict markers>>
+ that you need to resolve.
+
+[NOTE]
+================================
+Even if Git successfully merges both sides with no conflicts, it's
+possible to end up with code that doesn't work. For example, this can
+happen if one side renames a function, and the other side adds a call to
+the old function. This is called a "semantic merge conflict".
+================================
+
+[[markers]]
+MERGE CONFLICT MARKERS
+----------------------
+
+When there's a merge conflict, Git will update the conflicted file
+to include merge conflict markers `<<<<<<<`, `=======`, and `>>>>>>>`.
+For example, here's a merge conflict where both sides edited a list of
+fruits in different ways -- one side added "cherry" and the other side
+added "banana":
+
+----
+FRUITS = [
+ "apple",
+<<<<<<< HEAD
+ "cherry",
+=======
+ "banana",
+>>>>>>> add-fruit
+ "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 same thing.
+
+
+[[example]]
+EXAMPLE OF RESOLVING A MERGE CONFLICT
+-------------------------------------
+
+If you see this in your code during a merge conflict:
+
+----
+FRUITS = [
+ "apple",
+<<<<<<< HEAD
+ "cherry",
+=======
+ "banana",
+>>>>>>> add-fruit
+ "mango",
+ "orange",
+]
+----
+
+Then you might edit that part of the code like this,
+which includes the fruits from both sides of the conflict:
+
+----
+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.
+
+* You can set the configuration variable `merge.conflictstyle=diff3`.
+ See <<diff3,DIFF3>> below for more.
+
+* `git log --merge -p <filename>` will list all commits which
+ caused the merge conflict for `<filename>`, and the diff
+ of how they changed the file.
+
+* Look at the original files. `git show :1:filename` shows the
+ common ancestor, `git show :2:filename` shows the "ours"
+ version, and `git show :3:filename` shows the "theirs"
+ version. See <<ours,"OURS" AND "THEIRS">> below for more on
+ "ours" and "theirs".
+
+Here are some ways to track your progress while handling a conflict:
+
+* Use `git status` to get a list of files with conflicts
+
+* Use `git diff --check` to make sure you haven't left any merge
+ conflict markers in a file by accident. It will print "leftover
+ conflict marker" if it finds any.
+
+* Use `git diff AUTO_MERGE` to show what changes you've made so far to
+ resolve the conflicts.
+ See <<automerge,EXAMPLE OF USING `AUTO_MERGE`>> below for more.
+
+[[git_status]]
+EXAMPLE: GIT STATUS OUTPUT
+--------------------------
+
+When you're in a merge conflict, you can find out what commands to run
+to handle the conflict by running `git status`.
+
+For example, this `git status` output tells you that:
+
+* `git rebase --abort` will safely bring your branch back to its
+ original state
+* you should run `git rebase --continue` when you're done resolving all
+ the conflicts
+* the conflicts in `fruits.py` haven't been marked as resolved
+
+----
+$ git status
+You are currently rebasing branch 'main' on '58a9fcc'.
+ (fix conflicts and then run "git rebase --continue")
+ (use "git rebase --skip" to skip this patch)
+ (use "git rebase --abort" to check out the original branch)
+
+Unmerged paths:
+ (use "git restore --staged <file>..." to unstage)
+ (use "git add <file>..." to mark resolution)
+ both modified: fruits.py
+----
+
+
+[[diff3]]
+DIFF3
+-----
+
+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`.
+This extra context can make it much easier to understand what's
+happening in a merge conflict.
+
+Here's an example of what a merge conflict would look like when using
+`diff3`. There's an extra section (between `|||||||` and `=======`)
+with the original code.
+
+With this view, you can see that both sides fixed a spelling
+mistake in "mango", and each added one fruit to the list.
+
+----
+FRUITS = [
+ "apple",
+<<<<<<< HEAD
+ "cherry",
+ "mango",
+||||||| 1c22e48
+ "mangoooo",
+=======
+ "banana",
+ "mango",
+>>>>>>> add-fruit
+ "orange",
+]
+----
+
+[NOTE]
+================================
+`zdiff3` is an alternative to `diff3` that makes the merge conflict
+shorter by making it more ambiguous.
+================================
+
+[[ours]]
+"OURS" AND "THEIRS"
+-------------------
+
+Sometimes during a merge conflict, Git will use the terms "ours" and
+"theirs" (or "us" and "them"). For example, `git status` might say that
+a file was `deleted by us`.
+
+"Ours" and "theirs" are both commits: "ours" is the current
+`HEAD` commit, and "theirs" is the other side being merged.
+
+The first part of a merge conflict (between `<<<<<<<` and `=======`) is
+from the "ours" side, and the second part (between `=======` and
+`>>>>>>>`) is from the "theirs" side.
+
+----
+FRUITS = [
+ "apple",
+<<<<<<< HEAD
+ "cherry", <- ours
+=======
+ "banana", <- theirs
+>>>>>>> add-fruit
+ "mango",
+ "orange",
+]
+----
+
+During a rebase, it can seem "upside down" because the "ours" commit is
+from the branch you're rebasing on (for instance `main` in `git rebase
+main`).
+
+These terms in Git all mean the same thing when dealing with a merge
+conflict:
+
+* "common ancestor" and "base". The files from this commit are "in stage 1".
+* "ours", "us", and `HEAD`. The files from this commit are "in stage 2".
+* "theirs", "them". The files from this commit are "in stage 3".
+
+If you're confused about what something like "deleted by us" means, it's
+often easiest to use some of the tools from
+<<tools,TOOLS FOR HANDLING MERGE CONFLICTS>> above to get more context.
+Finding the commit that deleted the file and seeing why is usually more
+helpful than trying to abstractly reason through what "us" means.
+
+[[automerge]]
+EXAMPLE OF USING `AUTO_MERGE`
+-----------------------------
+
+`git diff AUTO_MERGE` will show what changes you've made so far to
+resolve conflicts. `AUTO_MERGE` is a reference that Git creates during a
+merge. It contains the result of running the merge algorithm.
+
+For example, if we resolved the conflict by adding both "banana" and
+"cherry" in order, the diff would look like this:
+
+----
+ FRUITS = [
+ "apple",
+-<<<<<<< HEAD
+- "cherry",
+-=======
+ "banana",
+->>>>>>> add-fruit
++ "cherry",
+ "mango",
+ "orange",
+ ]
+----
+
+[NOTE]
+`AUTO_MERGE` is only set if you're using the default Git merge algorithm.
+
+
+SEE ALSO
+--------
+
+linkgit:git-revert[1]
+linkgit:git-merge[1]
+linkgit:git-rebase[1]
+linkgit:git-cherry-pick[1]
+linkgit:git-pull[1]
+linkgit:git-diff[1]
+
+GIT
+---
+
+Part of the linkgit:git[1] suite
diff --git a/Documentation/meson.build b/Documentation/meson.build
index f4854f802d..51647957e0 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -202,6 +202,7 @@ manpages = {
'gitfaq.adoc' : 7,
'gitglossary.adoc' : 7,
'gitpacking.adoc' : 7,
+ 'gitmergeconflicts.adoc' : 7,
'gitnamespaces.adoc' : 7,
'gitremote-helpers.adoc' : 7,
'gitrevisions.adoc' : 7,
diff --git a/command-list.txt b/command-list.txt
index 63ae2a67c9..f6e49c3c85 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -232,6 +232,7 @@ githooks userinterfaces
gitignore userinterfaces
gitk mainporcelain
gitmailmap userinterfaces
+gitmergeconflicts guide
gitmodules userinterfaces
gitnamespaces guide
gitprotocol-capabilities developerinterfaces
--
gitgitgadget
[PATCH v3 2/6] doc: git-merge: link to new merge conflicts guide
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
162 lines
14366 bytes
14366 bytes
From: Julia Evans <julia@jvns.ca> All of the info about merge conflicts has been moved to the new guide Signed-off-by: Julia Evans <julia@jvns.ca> --- Documentation/git-merge.adoc | 125 +---------------------------------- 1 file changed, 3 insertions(+), 122 deletions(-) diff --git a/Documentation/git-merge.adoc b/Documentation/git-merge.adoc index a055384ad6..5b7b41cd10 100644 --- a/Documentation/git-merge.adoc +++ b/Documentation/git-merge.adoc @@ -49,7 +49,8 @@ a log message from the user describing the changes. Before the operation, A merge stops if there's a conflict that cannot be resolved automatically or if `--no-commit` was provided when initiating the merge. At that point you can run `git merge --abort` or `git merge ---continue`. +--continue`. See linkgit:gitmergeconflicts[7] +(or `git help mergeconflicts`) for a guide to handling merge conflicts. `git merge --abort` will abort the merge process and try to reconstruct the pre-merge state. However, if there were uncommitted changes when the @@ -231,127 +232,6 @@ git merge v1.2.3^0 git merge --ff-only v1.2.3 ---- -HOW CONFLICTS ARE PRESENTED ---------------------------- - -During a merge, the working tree files are updated to reflect the result -of the merge. Among the changes made to the common ancestor's version, -non-overlapping ones (that is, you changed an area of the file while the -other side left that area intact, or vice versa) are incorporated in the -final result verbatim. When both sides made changes to the same area, -however, Git cannot randomly pick one side over the other, and asks you to -resolve it by leaving what both sides did to that area. - -By default, Git uses the same style as the one used by the "merge" program -from the RCS suite to present such a conflicted hunk, like this: - ------------- -Here are lines that are either unchanged from the common -ancestor, or cleanly resolved because only one side changed, -or cleanly resolved because both sides changed the same way. -<<<<<<< yours:sample.txt -Conflict resolution is hard; -let's go shopping. -======= -Git makes conflict resolution easy. ->>>>>>> theirs:sample.txt -And here is another line that is cleanly resolved or unmodified. ------------- - -The area where a pair of conflicting changes happened is marked with markers -+<<<<<<<+, `=======`, and +>>>>>>>+. The part before the `=======` -is typically your side, and the part afterwards is typically their side. - -The default format does not show what the original said in the conflicting -area. You cannot tell how many lines are deleted and replaced with -Barbie's remark on your side. The only thing you can tell is that your -side wants to say it is hard and you'd prefer to go shopping, while the -other side wants to claim it is easy. - -An alternative style can be used by setting the `merge.conflictStyle` -configuration variable to either `diff3` or `zdiff3`. In `diff3` -style, the above conflict may look like this: - ------------- -Here are lines that are either unchanged from the common -ancestor, or cleanly resolved because only one side changed, -<<<<<<< yours:sample.txt -or cleanly resolved because both sides changed the same way. -Conflict resolution is hard; -let's go shopping. -||||||| base:sample.txt -or cleanly resolved because both sides changed identically. -Conflict resolution is hard. -======= -or cleanly resolved because both sides changed the same way. -Git makes conflict resolution easy. ->>>>>>> theirs:sample.txt -And here is another line that is cleanly resolved or unmodified. ------------- - -while in `zdiff3` style, it may look like this: - ------------- -Here are lines that are either unchanged from the common -ancestor, or cleanly resolved because only one side changed, -or cleanly resolved because both sides changed the same way. -<<<<<<< yours:sample.txt -Conflict resolution is hard; -let's go shopping. -||||||| base:sample.txt -or cleanly resolved because both sides changed identically. -Conflict resolution is hard. -======= -Git makes conflict resolution easy. ->>>>>>> theirs:sample.txt -And here is another line that is cleanly resolved or unmodified. ------------- - -In addition to the +<<<<<<<+, `=======`, and +>>>>>>>+ markers, it uses -another +|||||||+ marker that is followed by the original text. You can -tell that the original just stated a fact, and your side simply gave in to -that statement and gave up, while the other side tried to have a more -positive attitude. You can sometimes come up with a better resolution by -viewing the original. - - -HOW TO RESOLVE CONFLICTS ------------------------- - -After seeing a conflict, you can do two things: - - * Decide not to merge. The only clean-ups you need are to reset - the index file to the `HEAD` commit to reverse 2. and to clean - up working tree changes made by 2. and 3.; `git merge --abort` - can be used for this. - - * Resolve the conflicts. Git will mark the conflicts in - the working tree. Edit the files into shape and - `git add` them to the index. Use `git commit` or - `git merge --continue` to seal the deal. The latter command - checks whether there is a (interrupted) merge in progress - before calling `git commit`. - -You can work through the conflict with a number of tools: - - * Use a mergetool. `git mergetool` to launch a graphical - mergetool which will work through the merge with you. - - * Look at the diffs. `git diff` will show a three-way diff, - highlighting changes from both the `HEAD` and `MERGE_HEAD` - versions. `git diff AUTO_MERGE` will show what changes you've - made so far to resolve textual conflicts. - - * Look at the diffs from each branch. `git log --merge -p <path>` - will show diffs first for the `HEAD` version and then the - `MERGE_HEAD` version. - - * Look at the originals. `git show :1:filename` shows the - common ancestor, `git show :2:filename` shows the `HEAD` - version, and `git show :3:filename` shows the `MERGE_HEAD` - version. - - EXAMPLES -------- @@ -406,6 +286,7 @@ linkgit:git-reset[1], linkgit:git-diff[1], linkgit:git-ls-files[1], linkgit:git-add[1], linkgit:git-rm[1], linkgit:git-mergetool[1] +linkgit:gitmergeconflicts[7] GIT --- -- gitgitgadget
[PATCH v3 3/6] doc: git-rebase: link to new merge conflicts guide
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
55 lines
9998 bytes
9998 bytes
From: Julia Evans <julia@jvns.ca>
Remove some of the detail about how to handle a merge conflict, since
it's explained in detail in the new guide, and there probably isn't
enough detail anyway.
Leave the steps since rebase is special and has a `--skip` option which
the other commands which cause merge conflicts don't have.
Signed-off-by: Julia Evans <julia@jvns.ca>
---
Documentation/git-rebase.adoc | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-rebase.adoc b/Documentation/git-rebase.adoc
index f6c22d1598..da70aff498 100644
--- a/Documentation/git-rebase.adoc
+++ b/Documentation/git-rebase.adoc
@@ -46,10 +46,7 @@ If there is a merge conflict during this process, `git rebase` will stop at the
first problematic commit and leave conflict markers. If this happens, you can do
one of these things:
-1. Resolve the conflict. You can use `git diff` to find the markers (<<<<<<)
- and make edits to resolve the conflict. For each file you edit, you need to
- tell Git that the conflict has been resolved. You can mark the conflict as
- resolved with `git add <filename>`. After resolving all of the conflicts,
+1. Resolve the conflict. After resolving all of the conflicts,
you can continue the rebasing process with
git rebase --continue
@@ -62,6 +59,9 @@ one of these things:
git rebase --skip
+See linkgit:gitmergeconflicts[7] (or `git help mergeconflicts`)
+for a full guide to handling merge conflicts.
+
If you don't specify an `<upstream>` to rebase onto, the upstream configured in
`branch.<name>.remote` and `branch.<name>.merge` options will be used (see
linkgit:git-config[1] for details) and the `--fork-point` option is
@@ -1284,6 +1284,11 @@ include::includes/cmd-config-section-all.adoc[]
include::config/rebase.adoc[]
include::config/sequencer.adoc[]
+SEE ALSO
+--------
+
+linkgit:gitmergeconflicts[7]
+
GIT
---
Part of the linkgit:git[1] suite
--
gitgitgadget
[PATCH v3 4/6] doc: git-revert: link to new merge conflicts guide
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
33 lines
8835 bytes
8835 bytes
From: Julia Evans <julia@jvns.ca> Signed-off-by: Julia Evans <julia@jvns.ca> --- Documentation/git-revert.adoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/git-revert.adoc b/Documentation/git-revert.adoc index ffba365e63..bb0f859f66 100644 --- a/Documentation/git-revert.adoc +++ b/Documentation/git-revert.adoc @@ -31,6 +31,10 @@ both will discard uncommitted changes in your working directory. See "Reset, restore and revert" in linkgit:git[1] for the differences between the three commands. +Reverting a commit may result in a merge conflict. +See linkgit:gitmergeconflicts[7] (or `git help mergeconflicts`) +for a guide to handling merge conflicts. + OPTIONS ------- <commit>...:: @@ -162,6 +166,7 @@ include::config/revert.adoc[] SEE ALSO -------- linkgit:git-cherry-pick[1] +linkgit:gitmergeconflicts[7] GIT --- -- gitgitgadget
[PATCH v3 5/6] doc: git-cherry-pick: link to new merge conflicts guide
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
46 lines
9383 bytes
9383 bytes
From: Julia Evans <julia@jvns.ca>
Remove the discussion of merge conflicts and replace it with a link to
the guide.
Signed-off-by: Julia Evans <julia@jvns.ca>
---
Documentation/git-cherry-pick.adoc | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-cherry-pick.adoc b/Documentation/git-cherry-pick.adoc
index f4cd8b9db7..069e434961 100644
--- a/Documentation/git-cherry-pick.adoc
+++ b/Documentation/git-cherry-pick.adoc
@@ -19,8 +19,7 @@ Given one or more existing commits, apply the change each one
introduces, recording a new commit for each. This requires your
working tree to be clean (no modifications from the HEAD commit).
-When it is not obvious how to apply a change, the following
-happens:
+When a merge conflict happens:
1. The current branch and `HEAD` pointer stay at the last commit
successfully made.
@@ -36,8 +35,8 @@ happens:
conflict markers `<<<<<<<` and `>>>>>>>`.
5. No other modifications are made.
-See linkgit:git-merge[1] for some hints on resolving such
-conflicts.
+See linkgit:gitmergeconflicts[7] (or `git help mergeconflicts`)
+for a guide to handling merge conflicts.
OPTIONS
-------
@@ -259,6 +258,7 @@ $ git cherry-pick -Xpatience topic^ <4>
SEE ALSO
--------
linkgit:git-revert[1]
+linkgit:gitmergeconflicts[7]
GIT
---
--
gitgitgadget
[PATCH v3 6/6] doc: git-pull: link to new merge conflicts guide
Author: "Julia Evans via GitGitGadget"
Date: Mon, 12 Oct 2026 14:53
Date: Mon, 12 Oct 2026 14:53
24 lines
8711 bytes
8711 bytes
From: Julia Evans <julia@jvns.ca> Signed-off-by: Julia Evans <julia@jvns.ca> --- Documentation/git-pull.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/git-pull.adoc b/Documentation/git-pull.adoc index 88f4fd3926..73f6d460bb 100644 --- a/Documentation/git-pull.adoc +++ b/Documentation/git-pull.adoc @@ -38,7 +38,8 @@ or `pull.ff` with your preferred behaviour. If there's a merge conflict during the merge or rebase that you don't want to handle, you can safely abort it with `git merge --abort` or -`git rebase --abort`. +`git rebase --abort`. See linkgit:gitmergeconflicts[7] +(or `git help mergeconflicts`) for a guide to handling merge conflicts. OPTIONS ------- -- gitgitgadget
Re: [PATCH v3 0/6] [doc] Add new page on merge conflicts
Author: "D. Ben Knoble"
Date: Mon, 12 Oct 2026 15:53
Date: Mon, 12 Oct 2026 15:53
39 lines
10423 bytes
10423 bytes
On Mon, Oct 12, 2026 at 10:53 AM Julia Evans via GitGitGadget <gitgitgadget@gmail.com> wrote: > > Range-diff vs v2: > > 1: ab0344f947 ! 1: 7aa0ae7ec3 doc: add new gitmergeconflicts man page > @@ Commit message > place, since it's a really nice example of a place Git has a consistent > interface between similar commands. > > + Only discuss merge, rebase, cherry-pick, and revert for now even though > + there are other ways that merge conflicts can happen because it's > + awkward to talk about `am`, `apply`, and `checkout -m`. > + > Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com> > - Reviewed-by: D. Ben Knoble <ben.knoble+github@gmail.com> > - Reviewed-by: Patrick Steinhardt <ps@pks.im> > + Helped-by: D. Ben Knoble <ben.knoble+github@gmail.com> Maybe this got lost in the shuffle, but I do prefer to use <ben.knoble@gmail.com> for Git these days, thanks! > + Helped-by: Patrick Steinhardt <ps@pks.im> > + Signed-off-by: Julia Evans <julia@jvns.ca> > + Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com> > Signed-off-by: Julia Evans <julia@jvns.ca> I don't *think* we need your sign-off twice here, but maybe you intended to communicate something by this ordering? I confess I'm not sure what it would be ':D -- D. Ben Knoble
Re: [PATCH v3 1/6] doc: add new gitmergeconflicts man page
Author: Junio C Hamano
Date: Mon, 12 Oct 2026 18:16
Date: Mon, 12 Oct 2026 18:16
225 lines
17359 bytes
17359 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Julia Evans <julia@jvns.ca>
>
> Introduce a new page, `gitmergeconflicts`, that explains the process of
> handling a merge conflict in a way that addresses the following issues,
> which came from feedback from Git users on the current explanation of
> merge conflicts in the `git merge` man page:
>
> - The process for resolving a merge conflict is only explained in the
> ...
> - It sometimes uses the term "area" and sometimes uses the term "hunk"
It looks a bit annoying that these sentences in the enumeration all
lack their full stops.
> Only discuss merge, rebase, cherry-pick, and revert for now even though
> there are other ways that merge conflicts can happen because it's
> awkward to talk about `am`, `apply`, and `checkout -m`.
I do not know "because it's awkward" is a good justification,
though. "awkward" why?
It might be tempting to omit some commands that are less common for
new users, but we are touching the main part of the technical manual
that are meant ot be used by everybody, so that is not a good reason
to choose covering some but not others.
I however agree that it is better to avoid appearing to be complete
and leaving others (including future ones we add) with "any other
command that does a merge" as this round of document gives.
> diff --git a/Documentation/gitmergeconflicts.adoc b/Documentation/gitmergeconflicts.adoc
> ...
> +There are 3 ways to handle a merge conflict:
> +
> +* Resolve the conflict. (see <<resolve,HOW TO RESOLVE A MERGE CONFLICT>>
> + below for details)
> +* 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.
> +* Or (if you're in a multi-step rebase or cherry-pick) skip the problematic
> + commit with the appropriate `--skip` command
The third entry is a nice addition. multi-step anything are the
same, including revert, right? I'd recommend updating it to
something like "if you are in a multi-step operation like `rebase`"
in the same spirit as the "or any other command" change you made at
the beginning of this file.
> +[NOTE]
> +================================
> +Even if Git successfully merges both sides with no conflicts, it's
> +possible to end up with code that doesn't work. For example, this can
> +happen if one side renames a function, and the other side adds a call to
> +the old function. This is called a "semantic merge conflict".
> +================================
OK.
> +When there's a merge conflict, Git will update the conflicted file
> +to include merge conflict markers `<<<<<<<`, `=======`, and `>>>>>>>`.
> +For example, here's a merge conflict where both sides edited a list of
> +fruits in different ways -- one side added "cherry" and the other side
> +added "banana":
You added "-- one side added ..." at the end, which I think sends a
wrong message. With rcs-merge style conflict, you cannot simply
tell, because it is ambiguous. The original may have had both
banana and cherry, in which case the sample output shows the result
of one side removing banana and the other side removing cherry.
The only thing you can say from the sample output below is in the
current state "one side has cherry where the other side has banana,
and everything else is the same". You cannot say more without
seeing diff3 style conflict.
> +----
> +FRUITS = [
> + "apple",
> +<<<<<<< HEAD
> + "cherry",
> +=======
> + "banana",
> +>>>>>>> add-fruit
> + "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.
> +[[example]]
> +EXAMPLE OF RESOLVING A MERGE CONFLICT
> +-------------------------------------
> +
> +If you see this in your code during a merge conflict:
> +
> +----
> +FRUITS = [
> + "apple",
> +<<<<<<< HEAD
> + "cherry",
> +=======
> + "banana",
> +>>>>>>> add-fruit
> + "mango",
> + "orange",
> +]
> +----
> +
> +Then you might edit that part of the code like this,
> +which includes the fruits from both sides of the conflict:
> +
> +----
> +FRUITS = [
> + "apple",
> + "banana",
> + "cherry",
> + "mango",
> + "orange",
> +]
> +----
So, this is one possible resolution. We cannot tell if it is the
correct one.
> +[[tools]]
> +TOOLS FOR HANDLING MERGE CONFLICTS
> +----------------------------------
> +
> +Here are some ways to get extra context while handling a merge conflict:
> ...
The incremental changes to this list looks good.
> +[[diff3]]
> +DIFF3
> +-----
> +
> +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`.
> +This extra context can make it much easier to understand what's
> +happening in a merge conflict.
> +
> +Here's an example of what a merge conflict would look like when using
> +`diff3`. There's an extra section (between `|||||||` and `=======`)
> +with the original code.
> +
> +With this view, you can see that both sides fixed a spelling
> +mistake in "mango", and each added one fruit to the list.
> +
> +----
> +FRUITS = [
> + "apple",
> +<<<<<<< HEAD
> + "cherry",
> + "mango",
> +||||||| 1c22e48
> + "mangoooo",
> +=======
> + "banana",
> + "mango",
> +>>>>>>> add-fruit
> + "orange",
> +]
> +----
THis is a great example.
But an even better example would be to give this:
FRUITS = [
"apple",
<<<<<<< HEAD
"cherry",
"mango",
||||||| 1c22e48
"banana",
"cherry",
"mangoooo",
=======
"banana",
"mango",
>>>>>>> add-fruit
"orange",
]
and tell the readers that that the correct resolution is to have
"apply, mango, orange", as each of cherry and banana was removed by
one side while the other side did not touch it. Having cherry and
banana in the result is a tempting but not always correct conclusion
unexperienced people would draw from the rcs-merge style output that
is ambiguous, and here is a great place to teach it in this flow.
Especially because it would make it stand out that the point of
diff3's verboseness compared to the rcs-merge output is to
disambiguate two cases. If you start from ABCmO and one side has
ABMO while the other side has ACMO, the right resolution would be
AMO (the above case I added), but if your starting point were AmO
and the two sides ends with ABMO and ACMO respectively, the right
resolution would be ABCMO. The rcs-merge output does not tell you
which is more likely to be correct, diff3 disambiguates these two
cases by being more verbose.
And telling that value of diff3 is about disambiguating is valuable
when ...
> +[NOTE]
> +================================
> +`zdiff3` is an alternative to `diff3` that makes the merge conflict
> +shorter by making it more ambiguous.
> +================================
... this note tells the readers that zdiff3 is a ambigous variant of
diff3, hinting its flaw.
Re: [PATCH v3 0/6] [doc] Add new page on merge conflicts
Author: Junio C Hamano
Date: Mon, 12 Oct 2026 18:17
Date: Mon, 12 Oct 2026 18:17
22 lines
10472 bytes
10472 bytes
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes: > Changed in v2: > > * Explain what a merge conflict is (thanks to Junio & Ben) > * rewrite the "ours" vs "theirs" section (thanks to Patrick for the > comments) > * add git log --merge (thanks to Ben) > * Leave most of the content of git cherry-pick as-is, to make this patch > set smaller (thanks to Junio) > * remove the SYNOPSIS since hopefully that won't be required anymore by the > time this is merged > * Fix a typo in git revert (s/reverted conflict/reverted commit/) > * 's/the the/the/' (thanks to Patrick) > * s/[doc] Thing/doc: thing/ in commit messages (thanks to Tuomas)' > * squash the commit fixing the linter error (thanks to Junio) > * list reviewers in Reviewed-by I had some comments on diff3 in [1/6]; everything else looked good. Thanks.
Re: [PATCH v3 0/6] [doc] Add new page on merge conflicts
Author: Junio C Hamano
Date: Mon, 12 Oct 2026 18:37
Date: Mon, 12 Oct 2026 18:37
105 lines
13676 bytes
13676 bytes
Junio C Hamano <gitster@pobox.com> writes:
> I had some comments on diff3 in [1/6]; everything else looked good.
Here is a restatement of my [1/6] review in a squashable patch form.
The second hunk arond l.77 replaces "code" with "lines", as not
everybody using Git are writing program code, which is not what I
mentioned earlier. There are parts that talk about programs and
code, while other parts that talk about lines, so the mixture is
already there, but I think this part does not have to be specific
to code, but just applicable to anything that is line oriented.
The main part of this change is the updated diff3 example. It
reveals that the situation was different from naive interpretation
of an earlier (ambiguous) example showed. This should help readers
appreciate the extra information diff3 format supplies.
Documentation/gitmergeconflicts.adoc | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git c/Documentation/gitmergeconflicts.adoc w/Documentation/gitmergeconflicts.adoc
index 3c6eaaddf8..eeeeac85c0 100644
--- c/Documentation/gitmergeconflicts.adoc
+++ w/Documentation/gitmergeconflicts.adoc
@@ -60,8 +60,9 @@ MERGE CONFLICT MARKERS
When there's a merge conflict, Git will update the conflicted file
to include merge conflict markers `<<<<<<<`, `=======`, and `>>>>>>>`.
For example, here's a merge conflict where both sides edited a list of
-fruits in different ways -- one side added "cherry" and the other side
-added "banana":
+fruits in different ways, and ended up in different states. One side
+has "banana" but not "cherry", and the other side has "cherry", but
+not "banana".
----
FRUITS = [
@@ -76,8 +77,8 @@ FRUITS = [
]
----
-The code from one side of the merge conflict is between `<<<<<<<` and
-`=======`, and the code for the other side is between `=======` and
+The lines from one side of the merge conflict are between `<<<<<<<` and
+`=======`, and the lines from the other side are between `=======` and
`>>>>>>>`. See <<ours,"OURS" AND "THEIRS">> below for a full explanation
of which side is which.
@@ -121,8 +122,8 @@ FRUITS = [
]
----
-Then you might edit that part of the code like this,
-which includes the fruits from both sides of the conflict:
+Then you might edit that part of the code like this, to take
+all the fruits from both sides of the conflict:
----
FRUITS = [
@@ -208,15 +209,15 @@ DIFF3
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`.
-This extra context can make it much easier to understand what's
-happening in a merge conflict.
+This extra context can make it easier to understand what's
+happening in a merge conflict and avoid mismerges.
Here's an example of what a merge conflict would look like when using
`diff3`. There's an extra section (between `|||||||` and `=======`)
with the original code.
With this view, you can see that both sides fixed a spelling
-mistake in "mango", and each added one fruit to the list.
+mistake in "mango", and each removed one fruit from the list.
----
FRUITS = [
@@ -225,15 +226,24 @@ FRUITS = [
"cherry",
"mango",
||||||| 1c22e48
+ "banana",
+ "cherry",
"mangoooo",
=======
- "banana",
"mango",
>>>>>>> add-fruit
"orange",
]
----
+In the default format, you would see this conflict as shown before,
+i.e., "one side has 'banana', the other side has 'cherry', everything
+else is the same". But presented this way, we would realize that the
+conflict resolution to keep "banana" and "cherry" we showed earlier
+was incorrect. Rather, we want to drop "banana", and "cherry" and
+keep the "mango" with corrected spellings. The `diff3` format is more
+unambiguous by being more verbose.
+
[NOTE]
================================
`zdiff3` is an alternative to `diff3` that makes the merge conflict
Re: [PATCH v3 1/6] doc: add new gitmergeconflicts man page
Author: Junio C Hamano
Date: Wed, 14 Oct 2026 22:08
Date: Wed, 14 Oct 2026 22:08
28 lines
11012 bytes
11012 bytes
"Julia Evans" <julia@jvns.ca> writes: >> I do not know "because it's awkward" is a good justification, >> though. "awkward" why? > > It's because `apply` and `am` can also apply patches, and that's a whole > separate topic than explaining the 3-way merge. I think explaining the > difference between applying a patch and doing a 3-way merge could > be interesting to do in the future but this is already quite a big patch > series. I do not quite follow. "apply -3" is making a 3-way merge among the state _your_ working tree is in, the state shown as the preimage in the patch (i.e., before the patch author had the change they gave you in the patch), and the state shown as the postimage in the patch (i.e., after the patch author made the change). It is no different from the case where cherry-picking the change the patch author had stopped in conflict if (1) the machinery did find the necessary preimage blobs and (2) the 3way application did stop in a conflict. >> I however agree that it is better to avoid appearing to be complete >> and leaving others (including future ones we add) with "any other >> command that does a merge" as this round of document gives. Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads