]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-merge-tree.txt
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / Documentation / git-merge-tree.txt
CommitLineData
c16e30c0
JH
1git-merge-tree(1)
2=================
3
4NAME
5----
1f0c3a29 6git-merge-tree - Perform merge without touching index or working tree
c16e30c0
JH
7
8
9SYNOPSIS
10--------
7791a1d9 11[verse]
a1a78119 12'git merge-tree' [--write-tree] [<options>] <branch1> <branch2>
1f0c3a29 13'git merge-tree' [--trivial-merge] <base-tree> <branch1> <branch2> (deprecated)
c16e30c0 14
1f0c3a29 15[[NEWMERGE]]
c16e30c0
JH
16DESCRIPTION
17-----------
1f0c3a29
EN
18
19This command has a modern `--write-tree` mode and a deprecated
20`--trivial-merge` mode. With the exception of the
21<<DEPMERGE,DEPRECATED DESCRIPTION>> section at the end, the rest of
22this documentation describes modern `--write-tree` mode.
23
24Performs a merge, but does not make any new commits and does not read
25from or write to either the working tree or index.
26
27The performed merge will use the same feature as the "real"
28linkgit:git-merge[1], including:
29
30 * three way content merges of individual files
31 * rename detection
32 * proper directory/file conflict handling
33 * recursive ancestor consolidation (i.e. when there is more than one
34 merge base, creating a virtual merge base by merging the merge bases)
35 * etc.
36
37After the merge completes, a new toplevel tree object is created. See
38`OUTPUT` below for details.
39
a1a78119
EN
40OPTIONS
41-------
42
7c48b278
EN
43-z::
44 Do not quote filenames in the <Conflicted file info> section,
45 and end each filename with a NUL character rather than
46 newline. Also begin the messages section with a NUL character
47 instead of a newline. See <<OUTPUT>> below for more information.
48
b520bc6c
EN
49--name-only::
50 In the Conflicted file info section, instead of writing a list
51 of (mode, oid, stage, path) tuples to output for conflicted
52 files, just provide a list of filenames with conflicts (and
53 do not list filenames multiple times if they have multiple
54 conflicting stages).
55
a1a78119
EN
56--[no-]messages::
57 Write any informational messages such as "Auto-merging <path>"
58 or CONFLICT notices to the end of stdout. If unspecified, the
59 default is to include these messages if there are merge
60 conflicts, and to omit them otherwise.
61
7976721d
EN
62--allow-unrelated-histories::
63 merge-tree will by default error out if the two branches specified
64 share no common history. This flag can be given to override that
65 check and make the merge proceed anyway.
66
1f0c3a29
EN
67[[OUTPUT]]
68OUTPUT
69------
70
a1a78119
EN
71For a successful merge, the output from git-merge-tree is simply one
72line:
73
74 <OID of toplevel tree>
75
76Whereas for a conflicted merge, the output is by default of the form:
1f0c3a29
EN
77
78 <OID of toplevel tree>
b520bc6c 79 <Conflicted file info>
a1a78119
EN
80 <Informational messages>
81
82These are discussed individually below.
1f0c3a29 83
a1a78119
EN
84[[OIDTLT]]
85OID of toplevel tree
86~~~~~~~~~~~~~~~~~~~~
87
88This is a tree object that represents what would be checked out in the
89working tree at the end of `git merge`. If there were conflicts, then
7c48b278
EN
90files within this tree may have embedded conflict markers. This section
91is always followed by a newline (or NUL if `-z` is passed).
a1a78119 92
7fa33388 93[[CFI]]
b520bc6c 94Conflicted file info
7fa33388
EN
95~~~~~~~~~~~~~~~~~~~~
96
b520bc6c
EN
97This is a sequence of lines with the format
98
99 <mode> <object> <stage> <filename>
100
101The filename will be quoted as explained for the configuration
102variable `core.quotePath` (see linkgit:git-config[1]). However, if
103the `--name-only` option is passed, the mode, object, and stage will
7c48b278
EN
104be omitted. If `-z` is passed, the "lines" are terminated by a NUL
105character instead of a newline character.
7fa33388 106
a1a78119
EN
107[[IM]]
108Informational messages
109~~~~~~~~~~~~~~~~~~~~~~
110
7c48b278
EN
111This always starts with a blank line (or NUL if `-z` is passed) to
112separate it from the previous sections, and then has free-form
113messages about the merge, such as:
a1a78119
EN
114
115 * "Auto-merging <file>"
116 * "CONFLICT (rename/delete): <oldfile> renamed...but deleted in..."
117 * "Failed to merge submodule <submodule> (<reason>)"
118 * "Warning: cannot merge binary files: <filename>"
1f0c3a29 119
7c48b278
EN
120Note that these free-form messages will never have a NUL character
121in or between them, even if -z is passed. It is simply a large block
122of text taking up the remainder of the output.
123
1f0c3a29
EN
124EXIT STATUS
125-----------
126
127For a successful, non-conflicted merge, the exit status is 0. When the
128merge has conflicts, the exit status is 1. If the merge is not able to
129complete (or start) due to some kind of error, the exit status is
130something other than 0 or 1 (and the output is unspecified).
131
132USAGE NOTES
133-----------
134
135This command is intended as low-level plumbing, similar to
136linkgit:git-hash-object[1], linkgit:git-mktree[1],
137linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
138linkgit:git-update-ref[1], and linkgit:git-mktag[1]. Thus, it can be
139used as a part of a series of steps such as:
140
141 NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
142 test $? -eq 0 || die "There were conflicts..."
143 NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
144 git update-ref $BRANCH1 $NEWCOMMIT
145
a1a78119
EN
146Note that when the exit status is non-zero, `NEWTREE` in this sequence
147will contain a lot more output than just a tree.
148
b520bc6c
EN
149For conflicts, the output includes the same information that you'd get
150with linkgit:git-merge[1]:
151
152 * what would be written to the working tree (the
153 <<OIDTLT,OID of toplevel tree>>)
154 * the higher order stages that would be written to the index (the
155 <<CFI,Conflicted file info>>)
156 * any messages that would have been printed to stdout (the
157 <<IM,Informational messages>>)
158
7260e872
EN
159MISTAKES TO AVOID
160-----------------
161
162Do NOT look through the resulting toplevel tree to try to find which
163files conflict; parse the <<CFI,Conflicted file info>> section instead.
164Not only would parsing an entire tree be horrendously slow in large
165repositories, there are numerous types of conflicts not representable by
166conflict markers (modify/delete, mode conflict, binary file changed on
167both sides, file/directory conflicts, various rename conflict
168permutations, etc.)
169
170Do NOT interpret an empty <<CFI,Conflicted file info>> list as a clean
171merge; check the exit status. A merge can have conflicts without having
172individual files conflict (there are a few types of directory rename
173conflicts that fall into this category, and others might also be added
174in the future).
175
176Do NOT attempt to guess or make the user guess the conflict types from
177the <<CFI,Conflicted file info>> list. The information there is
178insufficient to do so. For example: Rename/rename(1to2) conflicts (both
179sides renamed the same file differently) will result in three different
180file having higher order stages (but each only has one higher order
181stage), with no way (short of the <<IM,Informational messages>> section)
182to determine which three files are related. File/directory conflicts
183also result in a file with exactly one higher order stage.
184Possibly-involved-in-directory-rename conflicts (when
185"merge.directoryRenames" is unset or set to "conflicts") also result in
186a file with exactly one higher order stage. In all cases, the
187<<IM,Informational messages>> section has the necessary info, though it
188is not designed to be machine parseable.
189
190Do NOT assume that each paths from <<CFI,Conflicted file info>>, and
191the logical conflicts in the <<IM,Informational messages>> have a
192one-to-one mapping, nor that there is a one-to-many mapping, nor a
193many-to-one mapping. Many-to-many mappings exist, meaning that each
194path can have many logical conflict types in a single merge, and each
195logical conflict type can affect many paths.
196
197Do NOT assume all filenames listed in the <<IM,Informational messages>>
198section had conflicts. Messages can be included for files that have no
199conflicts, such as "Auto-merging <file>".
200
201AVOID taking the OIDS from the <<CFI,Conflicted file info>> and
202re-merging them to present the conflicts to the user. This will lose
203information. Instead, look up the version of the file found within the
204<<OIDTLT,OID of toplevel tree>> and show that instead. In particular,
205the latter will have conflict markers annotated with the original
206branch/commit being merged and, if renames were involved, the original
207filename. While you could include the original branch/commit in the
208conflict marker annotations when re-merging, the original filename is
209not available from the <<CFI,Conflicted file info>> and thus you would
210be losing information that might help the user resolve the conflict.
211
1f0c3a29
EN
212[[DEPMERGE]]
213DEPRECATED DESCRIPTION
214----------------------
215
216Per the <<NEWMERGE,DESCRIPTION>> and unlike the rest of this
217documentation, this section describes the deprecated `--trivial-merge`
218mode.
219
220Other than the optional `--trivial-merge`, this mode accepts no
221options.
222
223This mode reads three tree-ish, and outputs trivial merge results and
224conflicting stages to the standard output in a semi-diff format.
225Since this was designed for higher level scripts to consume and merge
226the results back into the index, it omits entries that match
227<branch1>. The result of this second form is similar to what
228three-way 'git read-tree -m' does, but instead of storing the results
229in the index, the command outputs the entries to the standard output.
230
231This form not only has limited applicability (a trivial merge cannot
232handle content merges of individual files, rename detection, proper
233directory/file conflict handling, etc.), the output format is also
234difficult to work with, and it will generally be less performant than
235the first form even on successful merges (especially if working in
236large repositories).
c16e30c0 237
c16e30c0
JH
238GIT
239---
9e1f0a85 240Part of the linkgit:git[1] suite