summaryrefslogtreecommitdiffstats
path: root/man1/git-merge-tree.1
blob: 4e49b66621a3fb30438f43a882f5a73129bdffc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
'\" t
.\"     Title: git-merge-tree
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 10/07/2022
.\"    Manual: Git Manual
.\"    Source: Git 2.38.0.15.gbbe21b64a0
.\"  Language: English
.\"
.TH "GIT\-MERGE\-TREE" "1" "10/07/2022" "Git 2\&.38\&.0\&.15\&.gbbe21b6" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-merge-tree \- Perform merge without touching index or working tree
.SH "SYNOPSIS"
.sp
.nf
\fIgit merge\-tree\fR [\-\-write\-tree] [<options>] <branch1> <branch2>
\fIgit merge\-tree\fR [\-\-trivial\-merge] <base\-tree> <branch1> <branch2> (deprecated)
.fi
.sp
.SH "DESCRIPTION"
.sp
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 modern \fB\-\-write\-tree\fR mode\&.
.sp
Performs a merge, but does not make any new commits and does not read from or write to either the working tree or index\&.
.sp
The performed merge will use the same feature as the "real" \fBgit-merge\fR(1), including:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
three way content merges of individual files
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
rename detection
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
proper directory/file conflict handling
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
recursive ancestor consolidation (i\&.e\&. when there is more than one merge base, creating a virtual merge base by merging the merge bases)
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
etc\&.
.RE
.sp
After the merge completes, a new toplevel tree object is created\&. See \fBOUTPUT\fR below for details\&.
.SH "OPTIONS"
.PP
\-z
.RS 4
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
the section called \(lqOUTPUT\(rq
below for more information\&.
.RE
.PP
\-\-name\-only
.RS 4
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)\&.
.RE
.PP
\-\-[no\-]messages
.RS 4
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\&.
.RE
.PP
\-\-allow\-unrelated\-histories
.RS 4
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\&.
.RE
.SH "OUTPUT"
.sp
For a successful merge, the output from git\-merge\-tree is simply one line:
.sp
.if n \{\
.RS 4
.\}
.nf
<OID of toplevel tree>
.fi
.if n \{\
.RE
.\}
.sp
Whereas for a conflicted merge, the output is by default of the form:
.sp
.if n \{\
.RS 4
.\}
.nf
<OID of toplevel tree>
<Conflicted file info>
<Informational messages>
.fi
.if n \{\
.RE
.\}
.sp
These are discussed individually below\&.
.SS "OID of toplevel tree"
.sp
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)\&.
.SS "Conflicted file info"
.sp
This is a sequence of lines with the format
.sp
.if n \{\
.RS 4
.\}
.nf
<mode> <object> <stage> <filename>
.fi
.if n \{\
.RE
.\}
.sp
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\&.
.SS "Informational messages"
.sp
This always starts with a blank line (or NUL if \fB\-z\fR is passed) to separate it from the previous sections, and then has free\-form messages about the merge, such as:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
"Auto\-merging <file>"
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
"CONFLICT (rename/delete): <oldfile> renamed\&...but deleted in\&..."
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
"Failed to merge submodule <submodule> (<reason>)"
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
"Warning: cannot merge binary files: <filename>"
.RE
.sp
Note that these free\-form messages will never have a NUL character in or between them, even if \-z is passed\&. It is simply a large block of text taking up the remainder of the output\&.
.SH "EXIT STATUS"
.sp
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)\&.
.SH "USAGE NOTES"
.sp
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:
.sp
.if n \{\
.RS 4
.\}
.nf
NEWTREE=$(git merge\-tree \-\-write\-tree $BRANCH1 $BRANCH2)
test $? \-eq 0 || die "There were conflicts\&.\&.\&."
NEWCOMMIT=$(git commit\-tree $NEWTREE \-p $BRANCH1 \-p $BRANCH2)
git update\-ref $BRANCH1 $NEWCOMMIT
.fi
.if n \{\
.RE
.\}
.sp
Note that when the exit status is non\-zero, \fBNEWTREE\fR in this sequence will contain a lot more output than just a tree\&.
.sp
For conflicts, the output includes the same information that you\(cqd get with \fBgit-merge\fR(1):
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
what would be written to the working tree (the
OID of toplevel tree)
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
the higher order stages that would be written to the index (the
Conflicted file info)
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
any messages that would have been printed to stdout (the
Informational messages)
.RE
.SH "MISTAKES TO AVOID"
.sp
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\&.)
.sp
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)\&.
.sp
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 file 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\&.
.sp
Do NOT assume that each paths 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\&.
.sp
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>"\&.
.sp
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\&.
.SH "DEPRECATED DESCRIPTION"
.sp
Per the DESCRIPTION and unlike the rest of this documentation, this section describes the deprecated \fB\-\-trivial\-merge\fR mode\&.
.sp
Other than the optional \fB\-\-trivial\-merge\fR, this mode accepts no options\&.
.sp
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\&.
.sp
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)\&.
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite