Home Explore Blog CI



git

3rd chunk of `Documentation/git-merge-tree.adoc`
a09bfe7a9c4a02d02548cf711fd999718f761dc39b1c1d7b0000000100000cf2
 section starts with a blank line to separate it from the previous
sections, and then only contains the <conflict-message> information
from the previous section (separated by newlines).  These are
non-stable strings that should not be parsed by scripts, and are just
meant for human consumption.  Also, note that while <conflict-message>
strings usually do not contain embedded newlines, they sometimes do.
(However, the free-form messages will never have an embedded NUL
character).  So, the entire block of information is meant for human
readers as an agglomeration of all conflict messages.

EXIT STATUS
-----------

For a successful, non-conflicted merge, the exit status is 0.  When the
merge has conflicts, the exit status is 1.  If the merge is not able to
complete (or start) due to some kind of error, the exit status is
something other than 0 or 1 (and the output is unspecified).  When
--stdin is passed, the return status is 0 for both successful and
conflicted merges, and something other than 0 or 1 if it cannot complete
all the requested merges.

USAGE NOTES
-----------

This command is intended as low-level plumbing, similar to
linkgit:git-hash-object[1], linkgit:git-mktree[1],
linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
linkgit:git-update-ref[1], and linkgit:git-mktag[1].  Thus, it can be
used as a part of a series of steps such as:

       vi message.txt
       BRANCH1=refs/heads/test
       BRANCH2=main
       NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2) || {
           echo "There were conflicts..." 1>&2
           exit 1
       }
       NEWCOMMIT=$(git commit-tree $NEWTREE -F message.txt \
           -p $BRANCH1 -p $BRANCH2)
       git update-ref $BRANCH1 $NEWCOMMIT

Note that when the exit status is non-zero, `NEWTREE` in this sequence
will contain a lot more output than just a tree.

For conflicts, the output includes the same information that you'd get
with linkgit:git-merge[1]:

  * what would be written to the working tree (the
    <<OIDTLT,OID of toplevel tree>>)
  * the higher order stages that would be written to the index (the
    <<CFI,Conflicted file info>>)
  * any messages that would have been printed to stdout (the
    <<IM,Informational messages>>)

[[INPUT]]
INPUT FORMAT
------------
'git merge-tree --stdin' input format is fully text based. Each line
has this format:

	[<base-commit> -- ]<branch1> <branch2>

If one line is separated by `--`, the string before the separator is
used for specifying a merge-base for the merge and the string after
the separator describes the branches to be merged.

MISTAKES TO AVOID
-----------------

Do NOT look through the resulting toplevel tree to try to find which
files conflict; parse the <<CFI,Conflicted file info>> section instead.
Not only would parsing an entire tree be horrendously slow in large
repositories, there are numerous types of conflicts not representable by
conflict markers (modify/delete, mode conflict, binary file changed on
both sides, file/directory conflicts, various rename conflict
permutations, etc.)

Do NOT interpret an empty <<CFI,Conflicted file info>> list as a clean
merge; check the exit status.  A merge can have conflicts without having
individual files conflict (there are a few types of directory rename
conflicts that fall into this category, and

Title: Git Merge Tree Exit Status, Usage, and Input Format
Summary
The git merge-tree command returns an exit status indicating success, conflict, or error, and its usage is demonstrated in a series of steps for performing a merge, and the input format for --stdin is described, along with warnings on how to correctly interpret the output and avoid common mistakes.