blob: f96f3ae3cd53f0b9344b3504fa60e5ddaf2de513 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Junio C Hamano3901ffb2006-06-26 23:46:536<meta name="generator" content="AsciiDoc 7.0.2" />
Junio C Hamano1a4e8412005-12-27 08:17:237<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a { color: blue; }
20a:visited { color: fuchsia; }
21
22em {
23 font-style: italic;
24}
25
26strong {
27 font-weight: bold;
28}
29
30tt {
31 color: navy;
32}
33
34h1, h2, h3, h4, h5, h6 {
35 color: #527bbd;
36 font-family: sans-serif;
37 margin-top: 1.2em;
38 margin-bottom: 0.5em;
39 line-height: 1.3;
40}
41
42h1 {
43 border-bottom: 2px solid silver;
44}
45h2 {
46 border-bottom: 2px solid silver;
47 padding-top: 0.5em;
48}
49
50div.sectionbody {
51 font-family: serif;
52 margin-left: 0;
53}
54
55hr {
56 border: 1px solid silver;
57}
58
59p {
60 margin-top: 0.5em;
61 margin-bottom: 0.5em;
62}
63
64pre {
65 padding: 0;
66 margin: 0;
67}
68
69span#author {
70 color: #527bbd;
71 font-family: sans-serif;
72 font-weight: bold;
73 font-size: 1.2em;
74}
75span#email {
76}
77span#revision {
78 font-family: sans-serif;
79}
80
81div#footer {
82 font-family: sans-serif;
83 font-size: small;
84 border-top: 2px solid silver;
85 padding-top: 0.5em;
86 margin-top: 4.0em;
87}
88div#footer-text {
89 float: left;
90 padding-bottom: 0.5em;
91}
92div#footer-badges {
93 float: right;
94 padding-bottom: 0.5em;
95}
96
97div#preamble,
98div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
99div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
100div.admonitionblock {
101 margin-right: 10%;
102 margin-top: 1.5em;
103 margin-bottom: 1.5em;
104}
105div.admonitionblock {
106 margin-top: 2.5em;
107 margin-bottom: 2.5em;
108}
109
110div.content { /* Block element content. */
111 padding: 0;
112}
113
114/* Block element titles. */
115div.title, caption.title {
116 font-family: sans-serif;
117 font-weight: bold;
118 text-align: left;
119 margin-top: 1.0em;
120 margin-bottom: 0.5em;
121}
122div.title + * {
123 margin-top: 0;
124}
125
126td div.title:first-child {
127 margin-top: 0.0em;
128}
129div.content div.title:first-child {
130 margin-top: 0.0em;
131}
132div.content + div.title {
133 margin-top: 0.0em;
134}
135
136div.sidebarblock > div.content {
137 background: #ffffee;
138 border: 1px solid silver;
139 padding: 0.5em;
140}
141
142div.listingblock > div.content {
143 border: 1px solid silver;
144 background: #f4f4f4;
145 padding: 0.5em;
146}
147
148div.quoteblock > div.content {
149 padding-left: 2.0em;
150}
151div.quoteblock .attribution {
152 text-align: right;
153}
154
155div.admonitionblock .icon {
156 vertical-align: top;
157 font-size: 1.1em;
158 font-weight: bold;
159 text-decoration: underline;
160 color: #527bbd;
161 padding-right: 0.5em;
162}
163div.admonitionblock td.content {
164 padding-left: 0.5em;
165 border-left: 2px solid silver;
166}
167
168div.exampleblock > div.content {
169 border-left: 2px solid silver;
170 padding: 0.5em;
171}
172
173div.verseblock div.content {
174 white-space: pre;
175}
176
177div.imageblock div.content { padding-left: 0; }
178div.imageblock img { border: 1px solid silver; }
179span.image img { border-style: none; }
180
181dl {
182 margin-top: 0.8em;
183 margin-bottom: 0.8em;
184}
185dt {
186 margin-top: 0.5em;
187 margin-bottom: 0;
188 font-style: italic;
189}
190dd > *:first-child {
191 margin-top: 0;
192}
193
194ul, ol {
195 list-style-position: outside;
196}
197ol.olist2 {
198 list-style-type: lower-alpha;
199}
200
201div.tableblock > table {
202 border-color: #527bbd;
203 border-width: 3px;
204}
205thead {
206 font-family: sans-serif;
207 font-weight: bold;
208}
209tfoot {
210 font-weight: bold;
211}
212
213div.hlist {
214 margin-top: 0.8em;
215 margin-bottom: 0.8em;
216}
217td.hlist1 {
218 vertical-align: top;
219 font-style: italic;
220 padding-right: 0.8em;
221}
222td.hlist2 {
223 vertical-align: top;
224}
225
226@media print {
227 div#footer-badges { display: none; }
228}
229include::./stylesheets/xhtml11-manpage.css[]
230/* Workarounds for IE6's broken and incomplete CSS2. */
231
232div.sidebar-content {
233 background: #ffffee;
234 border: 1px solid silver;
235 padding: 0.5em;
236}
237div.sidebar-title, div.image-title {
238 font-family: sans-serif;
239 font-weight: bold;
240 margin-top: 0.0em;
241 margin-bottom: 0.5em;
242}
243
244div.listingblock div.content {
245 border: 1px solid silver;
246 background: #f4f4f4;
247 padding: 0.5em;
248}
249
250div.quoteblock-content {
251 padding-left: 2.0em;
252}
253
254div.exampleblock-content {
255 border-left: 2px solid silver;
256 padding-left: 0.5em;
257}
258</style>
259<title>git-merge(1)</title>
260</head>
261<body>
262<div id="header">
263<h1>
264git-merge(1) Manual Page
265</h1>
266<h2>NAME</h2>
267<div class="sectionbody">
268<p>git-merge -
Junio C Hamano7c73c662007-01-19 00:37:50269 Join two or more development histories together
Junio C Hamano1a4e8412005-12-27 08:17:23270</p>
271</div>
272</div>
273<h2>SYNOPSIS</h2>
274<div class="sectionbody">
Junio C Hamanoee6d9612006-11-27 20:03:22275<div class="verseblock">
Junio C Hamano591dc6a2007-05-29 09:18:19276<div class="content"><em>git-merge</em> [-n] [--summary] [--no-commit] [--squash] [-s &lt;strategy&gt;]&#8230;
Junio C Hamano1974bf22007-10-31 05:57:20277 [-m &lt;msg&gt;] &lt;remote&gt; &lt;remote&gt;&#8230;
278<em>git-merge</em> &lt;msg&gt; HEAD &lt;remote&gt;&#8230;</div></div>
Junio C Hamano1a4e8412005-12-27 08:17:23279</div>
280<h2>DESCRIPTION</h2>
281<div class="sectionbody">
Junio C Hamanoee6d9612006-11-27 20:03:22282<p>This is the top-level interface to the merge machinery
Junio C Hamano1a4e8412005-12-27 08:17:23283which drives multiple merge strategy scripts.</p>
Junio C Hamano1974bf22007-10-31 05:57:20284<p>The second syntax (&lt;msg&gt; <tt>HEAD</tt> &lt;remote&gt;) is supported for
285historical reasons. Do not use it from the command line or in
286new scripts. It is the same as <tt>git merge -m &lt;msg&gt; &lt;remote&gt;</tt>.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23287</div>
288<h2>OPTIONS</h2>
289<div class="sectionbody">
290<dl>
291<dt>
Junio C Hamano591dc6a2007-05-29 09:18:19292--summary
293</dt>
294<dd>
295<p>
296 Show a diffstat at the end of the merge. The diffstat is also
297 controlled by the configuration option merge.diffstat.
298</p>
299</dd>
300<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23301-n, --no-summary
302</dt>
303<dd>
304<p>
305 Do not show diffstat at the end of the merge.
306</p>
307</dd>
308<dt>
309--no-commit
310</dt>
311<dd>
312<p>
313 Perform the merge but pretend the merge failed and do
314 not autocommit, to give the user a chance to inspect and
315 further tweak the merge result before committing.
316</p>
317</dd>
318<dt>
Junio C Hamano1b50ce92007-10-03 12:05:53319--commit
320</dt>
321<dd>
322<p>
323 Perform the merge and commit the result. This option can
324 be used to override --no-commit.
325</p>
326</dd>
327<dt>
Junio C Hamano3901ffb2006-06-26 23:46:53328--squash
329</dt>
330<dd>
331<p>
332 Produce the working tree and index state as if a real
333 merge happened, but do not actually make a commit or
334 move the <tt>HEAD</tt>, nor record <tt>$GIT_DIR/MERGE_HEAD</tt> to
335 cause the next <tt>git commit</tt> command to create a merge
336 commit. This allows you to create a single commit on
337 top of the current branch whose effect is the same as
338 merging another branch (or more in case of an octopus).
339</p>
340</dd>
341<dt>
Junio C Hamano1b50ce92007-10-03 12:05:53342--no-squash
343</dt>
344<dd>
345<p>
346 Perform the merge and commit the result. This option can
347 be used to override --squash.
348</p>
349</dd>
350<dt>
351--no-ff
352</dt>
353<dd>
354<p>
355 Generate a merge commit even if the merge resolved as a
356 fast-forward.
357</p>
358</dd>
359<dt>
360--ff
361</dt>
362<dd>
363<p>
364 Do not generate a merge commit if the merge resolved as
365 a fast-forward, only update the branch pointer. This is
366 the default behavior of git-merge.
367</p>
368</dd>
369<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23370-s &lt;strategy&gt;, --strategy=&lt;strategy&gt;
371</dt>
372<dd>
373<p>
374 Use the given merge strategy; can be supplied more than
375 once to specify them in the order they should be tried.
376 If there is no <tt>-s</tt> option, a built-in list of strategies
377 is used instead (<tt>git-merge-recursive</tt> when merging a single
378 head, <tt>git-merge-octopus</tt> otherwise).
379</p>
380</dd>
381<dt>
Junio C Hamano1974bf22007-10-31 05:57:20382-m &lt;msg&gt;
Junio C Hamano1a4e8412005-12-27 08:17:23383</dt>
384<dd>
385<p>
386 The commit message to be used for the merge commit (in case
387 it is created). The <tt>git-fmt-merge-msg</tt> script can be used
388 to give a good default for automated <tt>git-merge</tt> invocations.
389</p>
390</dd>
391<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23392&lt;remote&gt;
393</dt>
394<dd>
395<p>
Junio C Hamanoee6d9612006-11-27 20:03:22396 Other branch head merged into our branch. You need at
Junio C Hamano1a4e8412005-12-27 08:17:23397 least one &lt;remote&gt;. Specifying more than one &lt;remote&gt;
398 obviously means you are trying an Octopus.
399</p>
400</dd>
401</dl>
402</div>
403<h2>MERGE STRATEGIES</h2>
404<div class="sectionbody">
405<dl>
406<dt>
407resolve
408</dt>
409<dd>
410<p>
411 This can only resolve two heads (i.e. the current branch
412 and another branch you pulled from) using 3-way merge
413 algorithm. It tries to carefully detect criss-cross
414 merge ambiguities and is considered generally safe and
415 fast.
416</p>
417</dd>
418<dt>
419recursive
420</dt>
421<dd>
422<p>
423 This can only resolve two heads using 3-way merge
424 algorithm. When there are more than one common
425 ancestors that can be used for 3-way merge, it creates a
426 merged tree of the common ancestors and uses that as
427 the reference tree for the 3-way merge. This has been
428 reported to result in fewer merge conflicts without
429 causing mis-merges by tests done on actual merge commits
430 taken from Linux 2.6 kernel development history.
431 Additionally this can detect and handle merges involving
432 renames. This is the default merge strategy when
433 pulling or merging one branch.
434</p>
435</dd>
436<dt>
437octopus
438</dt>
439<dd>
440<p>
441 This resolves more than two-head case, but refuses to do
442 complex merge that needs manual resolution. It is
443 primarily meant to be used for bundling topic branch
444 heads together. This is the default merge strategy when
445 pulling or merging more than one branches.
446</p>
447</dd>
448<dt>
449ours
450</dt>
451<dd>
452<p>
453 This resolves any number of heads, but the result of the
454 merge is always the current branch head. It is meant to
455 be used to supersede old development history of side
456 branches.
457</p>
458</dd>
459</dl>
460<p>If you tried a merge which resulted in a complex conflicts and
461would want to start over, you can recover with
462<a href="git-reset.html">git-reset(1)</a>.</p>
463</div>
Junio C Hamano1e6e0062007-07-13 05:33:25464<h2>CONFIGURATION</h2>
465<div class="sectionbody">
466<dl>
467<dt>
468merge.summary
469</dt>
470<dd>
471<p>
472 Whether to include summaries of merged commits in newly
473 created merge commit. False by default.
474</p>
475</dd>
476<dt>
477merge.verbosity
478</dt>
479<dd>
480<p>
481 Controls the amount of output shown by the recursive merge
482 strategy. Level 0 outputs nothing except a final error
483 message if conflicts were detected. Level 1 outputs only
484 conflicts, 2 outputs conflicts and file changes. Level 5 and
485 above outputs debugging information. The default is level 2.
Junio C Hamano4fd58d42007-09-30 00:51:14486 Can be overridden by <em>GIT_MERGE_VERBOSITY</em> environment variable.
Junio C Hamano1e6e0062007-07-13 05:33:25487</p>
488</dd>
Junio C Hamano1b50ce92007-10-03 12:05:53489<dt>
490branch.&lt;name&gt;.mergeoptions
491</dt>
492<dd>
493<p>
494 Sets default options for merging into branch &lt;name&gt;. The syntax and
495 supported options are equal to that of git-merge, but option values
496 containing whitespace characters are currently not supported.
497</p>
498</dd>
Junio C Hamano1e6e0062007-07-13 05:33:25499</dl>
500</div>
Junio C Hamano1a4e8412005-12-27 08:17:23501<h2>HOW MERGE WORKS</h2>
502<div class="sectionbody">
503<p>A merge is always between the current <tt>HEAD</tt> and one or more
504remote branch heads, and the index file must exactly match the
505tree of <tt>HEAD</tt> commit (i.e. the contents of the last commit) when
506it happens. In other words, <tt>git-diff --cached HEAD</tt> must
507report no changes.</p>
508<div class="admonitionblock">
509<table><tr>
510<td class="icon">
511<div class="title">Note</div>
512</td>
513<td class="content">This is a bit of lie. In certain special cases, your index are
514allowed to be different from the tree of <tt>HEAD</tt> commit. The most
515notable case is when your <tt>HEAD</tt> commit is already ahead of what
516is being merged, in which case your index can have arbitrary
517difference from your <tt>HEAD</tt> commit. Otherwise, your index entries
518are allowed have differences from your <tt>HEAD</tt> commit that match
519the result of trivial merge (e.g. you received the same patch
520from external source to produce the same result as what you are
521merging). For example, if a path did not exist in the common
522ancestor and your head commit but exists in the tree you are
523merging into your repository, and if you already happen to have
524that path exactly in your index, the merge does not have to
525fail.</td>
526</tr></table>
527</div>
528<p>Otherwise, merge will refuse to do any harm to your repository
529(that is, it may fetch the objects from remote, and it may even
530update the local branch used to keep track of the remote branch
531with <tt>git pull remote rbranch:lbranch</tt>, but your working tree,
532<tt>.git/HEAD</tt> pointer and index file are left intact).</p>
533<p>You may have local modifications in the working tree files. In
534other words, <tt>git-diff</tt> is allowed to report changes.
535However, the merge uses your working tree as the working area,
536and in order to prevent the merge operation from losing such
537changes, it makes sure that they do not interfere with the
538merge. Those complex tables in read-tree documentation define
539what it means for a path to "interfere with the merge". And if
540your local modifications interfere with the merge, again, it
541stops before touching anything.</p>
542<p>So in the above two "failed merge" case, you do not have to
Junio C Hamano51c2ab02006-07-09 20:38:54543worry about loss of data --- you simply were not ready to do
Junio C Hamano1a4e8412005-12-27 08:17:23544a merge, so no merge happened at all. You may want to finish
545whatever you were in the middle of doing, and retry the same
546pull after you are done and ready.</p>
547<p>When things cleanly merge, these things happen:</p>
548<ol>
549<li>
550<p>
Junio C Hamano092f5f02007-08-02 07:23:38551The results are updated both in the index file and in your
552 working tree;
Junio C Hamano1a4e8412005-12-27 08:17:23553</p>
554</li>
555<li>
556<p>
Junio C Hamano092f5f02007-08-02 07:23:38557Index file is written out as a tree;
Junio C Hamano1a4e8412005-12-27 08:17:23558</p>
559</li>
560<li>
561<p>
Junio C Hamano092f5f02007-08-02 07:23:38562The tree gets committed; and
Junio C Hamano1a4e8412005-12-27 08:17:23563</p>
564</li>
565<li>
566<p>
Junio C Hamano092f5f02007-08-02 07:23:38567The <tt>HEAD</tt> pointer gets advanced.
Junio C Hamano1a4e8412005-12-27 08:17:23568</p>
569</li>
570</ol>
571<p>Because of 2., we require that the original state of the index
572file to match exactly the current <tt>HEAD</tt> commit; otherwise we
573will write out your local changes already registered in your
574index file along with the merge result, which is not good.
575Because 1. involves only the paths different between your
576branch and the remote branch you are pulling from during the
577merge (which is typically a fraction of the whole tree), you can
578have local modifications in your working tree as long as they do
579not overlap with what the merge updates.</p>
580<p>When there are conflicts, these things happen:</p>
581<ol>
582<li>
583<p>
584<tt>HEAD</tt> stays the same.
585</p>
586</li>
587<li>
588<p>
589Cleanly merged paths are updated both in the index file and
590 in your working tree.
591</p>
592</li>
593<li>
594<p>
595For conflicting paths, the index file records up to three
596 versions; stage1 stores the version from the common ancestor,
597 stage2 from <tt>HEAD</tt>, and stage3 from the remote branch (you
598 can inspect the stages with <tt>git-ls-files -u</tt>). The working
599 tree files have the result of "merge" program; i.e. 3-way
600 merge result with familiar conflict markers <tt>&lt;&lt;&lt; === &gt;&gt;&gt;</tt>.
601</p>
602</li>
603<li>
604<p>
605No other changes are done. In particular, the local
606 modifications you had before you started merge will stay the
607 same and the index entries for them stay as they were,
608 i.e. matching <tt>HEAD</tt>.
609</p>
610</li>
611</ol>
612<p>After seeing a conflict, you can do two things:</p>
613<ul>
614<li>
615<p>
616Decide not to merge. The only clean-up you need are to reset
617 the index file to the <tt>HEAD</tt> commit to reverse 2. and to clean
618 up working tree changes made by 2. and 3.; <tt>git-reset</tt> can
619 be used for this.
620</p>
621</li>
622<li>
623<p>
624Resolve the conflicts. <tt>git-diff</tt> would report only the
625 conflicting paths because of the above 2. and 3.. Edit the
Junio C Hamano89d4e0f2007-02-18 00:34:59626 working tree files into a desirable shape, <tt>git-add</tt> or <tt>git-rm</tt>
Junio C Hamano1a4e8412005-12-27 08:17:23627 them, to make the index file contain what the merge result
628 should be, and run <tt>git-commit</tt> to commit the result.
629</p>
630</li>
631</ul>
632</div>
633<h2>SEE ALSO</h2>
634<div class="sectionbody">
635<p><a href="git-fmt-merge-msg.html">git-fmt-merge-msg(1)</a>, <a href="git-pull.html">git-pull(1)</a></p>
636</div>
637<h2>Author</h2>
638<div class="sectionbody">
639<p>Written by Junio C Hamano &lt;junkio@cox.net&gt;</p>
640</div>
641<h2>Documentation</h2>
642<div class="sectionbody">
643<p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
644</div>
645<h2>GIT</h2>
646<div class="sectionbody">
647<p>Part of the <a href="git.html">git(7)</a> suite</p>
648</div>
649<div id="footer">
650<div id="footer-text">
Junio C Hamano1974bf22007-10-31 05:57:20651Last updated 31-Oct-2007 05:56:48 UTC
Junio C Hamano1a4e8412005-12-27 08:17:23652</div>
653</div>
654</body>
655</html>