2 .\" Title: git-merge-tree
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.44.0.rc1.17.g3e0d3cd5c7
10 .TH "GIT\-MERGE\-TREE" "1" "2024\-02\-15" "Git 2\&.44\&.0\&.rc1\&.17\&.g3" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-merge-tree \- Perform merge without touching index or working tree
35 \fIgit merge\-tree\fR [\-\-write\-tree] [<options>] <branch1> <branch2>
36 \fIgit merge\-tree\fR [\-\-trivial\-merge] <base\-tree> <branch1> <branch2> (deprecated)
41 This command has a modern \fB\-\-write\-tree\fR mode and a deprecated \fB\-\-trivial\-merge\fR mode\&. With the exception of the DEPRECATED DESCRIPTION section at the end, the rest of this documentation describes the modern \fB\-\-write\-tree\fR mode\&.
43 Performs a merge, but does not make any new commits and does not read from or write to either the working tree or index\&.
45 The performed merge will use the same features as the "real" \fBgit-merge\fR(1), including:
55 three way content merges of individual files
77 proper directory/file conflict handling
88 recursive ancestor consolidation (i\&.e\&. when there is more than one merge base, creating a virtual merge base by merging the merge bases)
102 After the merge completes, a new toplevel tree object is created\&. See \fBOUTPUT\fR below for details\&.
107 Do not quote filenames in the <Conflicted file info> section, and end each filename with a NUL character rather than newline\&. Also begin the messages section with a NUL character instead of a newline\&. See
108 the section called \(lqOUTPUT\(rq
109 below for more information\&.
114 In the Conflicted file info section, instead of writing a list of (mode, oid, stage, path) tuples to output for conflicted files, just provide a list of filenames with conflicts (and do not list filenames multiple times if they have multiple conflicting stages)\&.
119 Write any informational messages such as "Auto\-merging <path>" or CONFLICT notices to the end of stdout\&. If unspecified, the default is to include these messages if there are merge conflicts, and to omit them otherwise\&.
122 \-\-allow\-unrelated\-histories
124 merge\-tree will by default error out if the two branches specified share no common history\&. This flag can be given to override that check and make the merge proceed anyway\&.
127 \-\-merge\-base=<commit>
129 Instead of finding the merge\-bases for <branch1> and <branch2>, specify a merge\-base for the merge, and specifying multiple bases is currently not supported\&. This option is incompatible with
134 For a successful merge, the output from git\-merge\-tree is simply one line:
140 <OID of toplevel tree>
146 Whereas for a conflicted merge, the output is by default of the form:
152 <OID of toplevel tree>
153 <Conflicted file info>
154 <Informational messages>
160 These are discussed individually below\&.
162 However, there is an exception\&. If \fB\-\-stdin\fR is passed, then there is an extra section at the beginning, a NUL character at the end, and then all the sections repeat for each line of input\&. Thus, if the first merge is conflicted and the second is clean, the output would be of the form:
169 <OID of toplevel tree>
170 <Conflicted file info>
171 <Informational messages>
174 <OID of toplevel tree>
182 This is an integer status followed by a NUL character\&. The integer status is:
188 0: merge had conflicts
190 <0: something prevented the merge from running (e\&.g\&. access to repository
191 objects denied by filesystem)
196 .SS "OID of toplevel tree"
198 This is a tree object that represents what would be checked out in the working tree at the end of \fBgit merge\fR\&. If there were conflicts, then files within this tree may have embedded conflict markers\&. This section is always followed by a newline (or NUL if \fB\-z\fR is passed)\&.
199 .SS "Conflicted file info"
201 This is a sequence of lines with the format
207 <mode> <object> <stage> <filename>
213 The filename will be quoted as explained for the configuration variable \fBcore\&.quotePath\fR (see \fBgit-config\fR(1))\&. However, if the \fB\-\-name\-only\fR option is passed, the mode, object, and stage will be omitted\&. If \fB\-z\fR is passed, the "lines" are terminated by a NUL character instead of a newline character\&.
214 .SS "Informational messages"
216 This section provides informational messages, typically about conflicts\&. The format of the section varies significantly depending on whether \fB\-z\fR is passed\&.
218 If \fB\-z\fR is passed:
220 The output format is zero or more conflict informational records, each of the form:
226 <list\-of\-paths><conflict\-type>NUL<conflict\-message>NUL
232 where <list\-of\-paths> is of the form
238 <number\-of\-paths>NUL<path1>NUL<path2>NUL\&.\&.\&.<pathN>NUL
244 and includes paths (or branch names) affected by the conflict or informational message in <conflict\-message>\&. Also, <conflict\-type> is a stable string explaining the type of conflict, such as
265 "CONFLICT (rename/delete)"
276 "CONFLICT (submodule lacks merge base)"
290 and <conflict\-message> is a more detailed message about the conflict which often (but not always) embeds the <stable\-short\-type\-description> within it\&. These strings may change in future Git versions\&. Some examples:
300 "Auto\-merging <file>"
311 "CONFLICT (rename/delete): <oldfile> renamed\&...but deleted in\&..."
322 "Failed to merge submodule <submodule> (no merge base)"
333 "Warning: cannot merge binary files: <filename>"
336 If \fB\-z\fR is NOT passed:
338 This 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\&.
341 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\&.
344 This command is intended as low\-level plumbing, similar to \fBgit-hash-object\fR(1), \fBgit-mktree\fR(1), \fBgit-commit-tree\fR(1), \fBgit-write-tree\fR(1), \fBgit-update-ref\fR(1), and \fBgit-mktag\fR(1)\&. Thus, it can be used as a part of a series of steps such as:
350 NEWTREE=$(git merge\-tree \-\-write\-tree $BRANCH1 $BRANCH2)
351 test $? \-eq 0 || die "There were conflicts\&.\&.\&."
352 NEWCOMMIT=$(git commit\-tree $NEWTREE \-p $BRANCH1 \-p $BRANCH2)
353 git update\-ref $BRANCH1 $NEWCOMMIT
359 Note that when the exit status is non\-zero, \fBNEWTREE\fR in this sequence will contain a lot more output than just a tree\&.
361 For conflicts, the output includes the same information that you\(cqd get with \fBgit-merge\fR(1):
371 what would be written to the working tree (the
372 OID of toplevel tree)
383 the higher order stages that would be written to the index (the
384 Conflicted file info)
395 any messages that would have been printed to stdout (the
396 Informational messages)
400 \fIgit merge\-tree \-\-stdin\fR input format is fully text based\&. Each line has this format:
406 [<base\-commit> \-\- ]<branch1> <branch2>
412 If one line is separated by \fB\-\-\fR, 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\&.
413 .SH "MISTAKES TO AVOID"
415 Do NOT look through the resulting toplevel tree to try to find which files conflict; parse the 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\&.)
417 Do NOT interpret an empty 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 others might also be added in the future)\&.
419 Do NOT attempt to guess or make the user guess the conflict types from the Conflicted file info list\&. The information there is insufficient to do so\&. For example: Rename/rename(1to2) conflicts (both sides renamed the same file differently) will result in three different files having higher order stages (but each only has one higher order stage), with no way (short of the Informational messages section) to determine which three files are related\&. File/directory conflicts also result in a file with exactly one higher order stage\&. Possibly\-involved\-in\-directory\-rename conflicts (when "merge\&.directoryRenames" is unset or set to "conflicts") also result in a file with exactly one higher order stage\&. In all cases, the Informational messages section has the necessary info, though it is not designed to be machine parseable\&.
421 Do NOT assume that each path from Conflicted file info, and the logical conflicts in the Informational messages have a one\-to\-one mapping, nor that there is a one\-to\-many mapping, nor a many\-to\-one mapping\&. Many\-to\-many mappings exist, meaning that each path can have many logical conflict types in a single merge, and each logical conflict type can affect many paths\&.
423 Do NOT assume all filenames listed in the Informational messages section had conflicts\&. Messages can be included for files that have no conflicts, such as "Auto\-merging <file>"\&.
425 AVOID taking the OIDS from the Conflicted file info and re\-merging them to present the conflicts to the user\&. This will lose information\&. Instead, look up the version of the file found within the OID of toplevel tree and show that instead\&. In particular, the latter will have conflict markers annotated with the original branch/commit being merged and, if renames were involved, the original filename\&. While you could include the original branch/commit in the conflict marker annotations when re\-merging, the original filename is not available from the Conflicted file info and thus you would be losing information that might help the user resolve the conflict\&.
426 .SH "DEPRECATED DESCRIPTION"
428 Per the DESCRIPTION and unlike the rest of this documentation, this section describes the deprecated \fB\-\-trivial\-merge\fR mode\&.
430 Other than the optional \fB\-\-trivial\-merge\fR, this mode accepts no options\&.
432 This mode reads three tree\-ish, and outputs trivial merge results and conflicting stages to the standard output in a semi\-diff format\&. Since this was designed for higher level scripts to consume and merge the results back into the index, it omits entries that match <branch1>\&. The result of this second form is similar to what three\-way \fIgit read\-tree \-m\fR does, but instead of storing the results in the index, the command outputs the entries to the standard output\&.
434 This form not only has limited applicability (a trivial merge cannot handle content merges of individual files, rename detection, proper directory/file conflict handling, etc\&.), the output format is also difficult to work with, and it will generally be less performant than the first form even on successful merges (especially if working in large repositories)\&.
437 Part of the \fBgit\fR(1) suite