]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-merge-tree.txt
Merge branch 'jc/unleak-core-excludesfile'
[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
0a4f051f 22this documentation describes the modern `--write-tree` mode.
1f0c3a29
EN
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
6cc668c0 27The performed merge will use the same features as the "real"
1f0c3a29
EN
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
5f43cf5b 67--merge-base=<tree-ish>::
66265a69 68 Instead of finding the merge-bases for <branch1> and <branch2>,
4cc9eb33
KZ
69 specify a merge-base for the merge, and specifying multiple bases is
70 currently not supported. This option is incompatible with `--stdin`.
5f43cf5b
JS
71+
72As the merge-base is provided directly, <branch1> and <branch2> do not need
73to specify commits; trees are enough.
66265a69 74
1f0c3a29
EN
75[[OUTPUT]]
76OUTPUT
77------
78
a1a78119
EN
79For a successful merge, the output from git-merge-tree is simply one
80line:
81
82 <OID of toplevel tree>
83
84Whereas for a conflicted merge, the output is by default of the form:
1f0c3a29
EN
85
86 <OID of toplevel tree>
b520bc6c 87 <Conflicted file info>
a1a78119
EN
88 <Informational messages>
89
90These are discussed individually below.
1f0c3a29 91
ec1edbcb
EN
92However, there is an exception. If `--stdin` is passed, then there is
93an extra section at the beginning, a NUL character at the end, and then
94all the sections repeat for each line of input. Thus, if the first merge
95is conflicted and the second is clean, the output would be of the form:
96
97 <Merge status>
98 <OID of toplevel tree>
99 <Conflicted file info>
100 <Informational messages>
101 NUL
102 <Merge status>
103 <OID of toplevel tree>
104 NUL
105
106[[MS]]
107Merge status
108~~~~~~~~~~~~
109
110This is an integer status followed by a NUL character. The integer status is:
111
112 0: merge had conflicts
113 1: merge was clean
f7111175 114 <0: something prevented the merge from running (e.g. access to repository
ec1edbcb
EN
115 objects denied by filesystem)
116
a1a78119
EN
117[[OIDTLT]]
118OID of toplevel tree
119~~~~~~~~~~~~~~~~~~~~
120
121This is a tree object that represents what would be checked out in the
122working tree at the end of `git merge`. If there were conflicts, then
7c48b278
EN
123files within this tree may have embedded conflict markers. This section
124is always followed by a newline (or NUL if `-z` is passed).
a1a78119 125
7fa33388 126[[CFI]]
b520bc6c 127Conflicted file info
7fa33388
EN
128~~~~~~~~~~~~~~~~~~~~
129
b520bc6c
EN
130This is a sequence of lines with the format
131
132 <mode> <object> <stage> <filename>
133
134The filename will be quoted as explained for the configuration
135variable `core.quotePath` (see linkgit:git-config[1]). However, if
136the `--name-only` option is passed, the mode, object, and stage will
7c48b278
EN
137be omitted. If `-z` is passed, the "lines" are terminated by a NUL
138character instead of a newline character.
7fa33388 139
a1a78119
EN
140[[IM]]
141Informational messages
142~~~~~~~~~~~~~~~~~~~~~~
143
a9f5bb83
EN
144This section provides informational messages, typically about
145conflicts. The format of the section varies significantly depending
146on whether `-z` is passed.
147
148If `-z` is passed:
149
150The output format is zero or more conflict informational records, each
151of the form:
152
153 <list-of-paths><conflict-type>NUL<conflict-message>NUL
154
155where <list-of-paths> is of the form
156
157 <number-of-paths>NUL<path1>NUL<path2>NUL...<pathN>NUL
158
159and includes paths (or branch names) affected by the conflict or
160informational message in <conflict-message>. Also, <conflict-type> is a
161stable string explaining the type of conflict, such as
162
163 * "Auto-merging"
164 * "CONFLICT (rename/delete)"
165 * "CONFLICT (submodule lacks merge base)"
166 * "CONFLICT (binary)"
167
168and <conflict-message> is a more detailed message about the conflict which often
169(but not always) embeds the <stable-short-type-description> within it. These
170strings may change in future Git versions. Some examples:
a1a78119
EN
171
172 * "Auto-merging <file>"
173 * "CONFLICT (rename/delete): <oldfile> renamed...but deleted in..."
a9f5bb83 174 * "Failed to merge submodule <submodule> (no merge base)"
a1a78119 175 * "Warning: cannot merge binary files: <filename>"
1f0c3a29 176
a9f5bb83
EN
177If `-z` is NOT passed:
178
179This section starts with a blank line to separate it from the previous
180sections, and then only contains the <conflict-message> information
181from the previous section (separated by newlines). These are
182non-stable strings that should not be parsed by scripts, and are just
183meant for human consumption. Also, note that while <conflict-message>
184strings usually do not contain embedded newlines, they sometimes do.
185(However, the free-form messages will never have an embedded NUL
186character). So, the entire block of information is meant for human
187readers as an agglomeration of all conflict messages.
7c48b278 188
1f0c3a29
EN
189EXIT STATUS
190-----------
191
192For a successful, non-conflicted merge, the exit status is 0. When the
193merge has conflicts, the exit status is 1. If the merge is not able to
194complete (or start) due to some kind of error, the exit status is
ec1edbcb
EN
195something other than 0 or 1 (and the output is unspecified). When
196--stdin is passed, the return status is 0 for both successful and
197conflicted merges, and something other than 0 or 1 if it cannot complete
198all the requested merges.
1f0c3a29
EN
199
200USAGE NOTES
201-----------
202
203This command is intended as low-level plumbing, similar to
204linkgit:git-hash-object[1], linkgit:git-mktree[1],
205linkgit:git-commit-tree[1], linkgit:git-write-tree[1],
206linkgit:git-update-ref[1], and linkgit:git-mktag[1]. Thus, it can be
207used as a part of a series of steps such as:
208
209 NEWTREE=$(git merge-tree --write-tree $BRANCH1 $BRANCH2)
210 test $? -eq 0 || die "There were conflicts..."
211 NEWCOMMIT=$(git commit-tree $NEWTREE -p $BRANCH1 -p $BRANCH2)
212 git update-ref $BRANCH1 $NEWCOMMIT
213
a1a78119
EN
214Note that when the exit status is non-zero, `NEWTREE` in this sequence
215will contain a lot more output than just a tree.
216
b520bc6c
EN
217For conflicts, the output includes the same information that you'd get
218with linkgit:git-merge[1]:
219
220 * what would be written to the working tree (the
221 <<OIDTLT,OID of toplevel tree>>)
222 * the higher order stages that would be written to the index (the
223 <<CFI,Conflicted file info>>)
224 * any messages that would have been printed to stdout (the
225 <<IM,Informational messages>>)
226
501e3bab
KZ
227INPUT FORMAT
228------------
229'git merge-tree --stdin' input format is fully text based. Each line
230has this format:
231
232 [<base-commit> -- ]<branch1> <branch2>
233
234If one line is separated by `--`, the string before the separator is
235used for specifying a merge-base for the merge and the string after
236the separator describes the branches to be merged.
237
7260e872
EN
238MISTAKES TO AVOID
239-----------------
240
241Do NOT look through the resulting toplevel tree to try to find which
242files conflict; parse the <<CFI,Conflicted file info>> section instead.
243Not only would parsing an entire tree be horrendously slow in large
244repositories, there are numerous types of conflicts not representable by
245conflict markers (modify/delete, mode conflict, binary file changed on
246both sides, file/directory conflicts, various rename conflict
247permutations, etc.)
248
249Do NOT interpret an empty <<CFI,Conflicted file info>> list as a clean
250merge; check the exit status. A merge can have conflicts without having
251individual files conflict (there are a few types of directory rename
252conflicts that fall into this category, and others might also be added
253in the future).
254
255Do NOT attempt to guess or make the user guess the conflict types from
256the <<CFI,Conflicted file info>> list. The information there is
257insufficient to do so. For example: Rename/rename(1to2) conflicts (both
258sides renamed the same file differently) will result in three different
6cc668c0 259files having higher order stages (but each only has one higher order
7260e872
EN
260stage), with no way (short of the <<IM,Informational messages>> section)
261to determine which three files are related. File/directory conflicts
262also result in a file with exactly one higher order stage.
263Possibly-involved-in-directory-rename conflicts (when
264"merge.directoryRenames" is unset or set to "conflicts") also result in
265a file with exactly one higher order stage. In all cases, the
266<<IM,Informational messages>> section has the necessary info, though it
267is not designed to be machine parseable.
268
6cc668c0 269Do NOT assume that each path from <<CFI,Conflicted file info>>, and
7260e872
EN
270the logical conflicts in the <<IM,Informational messages>> have a
271one-to-one mapping, nor that there is a one-to-many mapping, nor a
272many-to-one mapping. Many-to-many mappings exist, meaning that each
273path can have many logical conflict types in a single merge, and each
274logical conflict type can affect many paths.
275
276Do NOT assume all filenames listed in the <<IM,Informational messages>>
277section had conflicts. Messages can be included for files that have no
278conflicts, such as "Auto-merging <file>".
279
280AVOID taking the OIDS from the <<CFI,Conflicted file info>> and
281re-merging them to present the conflicts to the user. This will lose
282information. Instead, look up the version of the file found within the
283<<OIDTLT,OID of toplevel tree>> and show that instead. In particular,
284the latter will have conflict markers annotated with the original
285branch/commit being merged and, if renames were involved, the original
286filename. While you could include the original branch/commit in the
287conflict marker annotations when re-merging, the original filename is
288not available from the <<CFI,Conflicted file info>> and thus you would
289be losing information that might help the user resolve the conflict.
290
1f0c3a29
EN
291[[DEPMERGE]]
292DEPRECATED DESCRIPTION
293----------------------
294
295Per the <<NEWMERGE,DESCRIPTION>> and unlike the rest of this
296documentation, this section describes the deprecated `--trivial-merge`
297mode.
298
299Other than the optional `--trivial-merge`, this mode accepts no
300options.
301
302This mode reads three tree-ish, and outputs trivial merge results and
303conflicting stages to the standard output in a semi-diff format.
304Since this was designed for higher level scripts to consume and merge
305the results back into the index, it omits entries that match
306<branch1>. The result of this second form is similar to what
307three-way 'git read-tree -m' does, but instead of storing the results
308in the index, the command outputs the entries to the standard output.
309
310This form not only has limited applicability (a trivial merge cannot
311handle content merges of individual files, rename detection, proper
312directory/file conflict handling, etc.), the output format is also
313difficult to work with, and it will generally be less performant than
314the first form even on successful merges (especially if working in
315large repositories).
c16e30c0 316
c16e30c0
JH
317GIT
318---
9e1f0a85 319Part of the linkgit:git[1] suite