blob: 230111bd381248256b984af75267ae5ade133b16 [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 -
269 Grand Unified Merge Driver
270</p>
271</div>
272</div>
273<h2>SYNOPSIS</h2>
274<div class="sectionbody">
275<p><em>git-merge</em> [-n] [--no-commit] [-s &lt;strategy&gt;]&#8230; &lt;msg&gt; &lt;head&gt; &lt;remote&gt; &lt;remote&gt;&#8230;</p>
276</div>
277<h2>DESCRIPTION</h2>
278<div class="sectionbody">
279<p>This is the top-level user interface to the merge machinery
280which drives multiple merge strategy scripts.</p>
281</div>
282<h2>OPTIONS</h2>
283<div class="sectionbody">
284<dl>
285<dt>
286-n, --no-summary
287</dt>
288<dd>
289<p>
290 Do not show diffstat at the end of the merge.
291</p>
292</dd>
293<dt>
294--no-commit
295</dt>
296<dd>
297<p>
298 Perform the merge but pretend the merge failed and do
299 not autocommit, to give the user a chance to inspect and
300 further tweak the merge result before committing.
301</p>
302</dd>
303<dt>
Junio C Hamano3901ffb2006-06-26 23:46:53304--squash
305</dt>
306<dd>
307<p>
308 Produce the working tree and index state as if a real
309 merge happened, but do not actually make a commit or
310 move the <tt>HEAD</tt>, nor record <tt>$GIT_DIR/MERGE_HEAD</tt> to
311 cause the next <tt>git commit</tt> command to create a merge
312 commit. This allows you to create a single commit on
313 top of the current branch whose effect is the same as
314 merging another branch (or more in case of an octopus).
315</p>
316</dd>
317<dt>
Junio C Hamano1a4e8412005-12-27 08:17:23318-s &lt;strategy&gt;, --strategy=&lt;strategy&gt;
319</dt>
320<dd>
321<p>
322 Use the given merge strategy; can be supplied more than
323 once to specify them in the order they should be tried.
324 If there is no <tt>-s</tt> option, a built-in list of strategies
325 is used instead (<tt>git-merge-recursive</tt> when merging a single
326 head, <tt>git-merge-octopus</tt> otherwise).
327</p>
328</dd>
329<dt>
330&lt;msg&gt;
331</dt>
332<dd>
333<p>
334 The commit message to be used for the merge commit (in case
335 it is created). The <tt>git-fmt-merge-msg</tt> script can be used
336 to give a good default for automated <tt>git-merge</tt> invocations.
337</p>
338</dd>
339<dt>
340&lt;head&gt;
341</dt>
342<dd>
343<p>
344 our branch head commit.
345</p>
346</dd>
347<dt>
348&lt;remote&gt;
349</dt>
350<dd>
351<p>
352 other branch head merged into our branch. You need at
353 least one &lt;remote&gt;. Specifying more than one &lt;remote&gt;
354 obviously means you are trying an Octopus.
355</p>
356</dd>
357</dl>
358</div>
359<h2>MERGE STRATEGIES</h2>
360<div class="sectionbody">
361<dl>
362<dt>
363resolve
364</dt>
365<dd>
366<p>
367 This can only resolve two heads (i.e. the current branch
368 and another branch you pulled from) using 3-way merge
369 algorithm. It tries to carefully detect criss-cross
370 merge ambiguities and is considered generally safe and
371 fast.
372</p>
373</dd>
374<dt>
375recursive
376</dt>
377<dd>
378<p>
379 This can only resolve two heads using 3-way merge
380 algorithm. When there are more than one common
381 ancestors that can be used for 3-way merge, it creates a
382 merged tree of the common ancestors and uses that as
383 the reference tree for the 3-way merge. This has been
384 reported to result in fewer merge conflicts without
385 causing mis-merges by tests done on actual merge commits
386 taken from Linux 2.6 kernel development history.
387 Additionally this can detect and handle merges involving
388 renames. This is the default merge strategy when
389 pulling or merging one branch.
390</p>
391</dd>
392<dt>
393octopus
394</dt>
395<dd>
396<p>
397 This resolves more than two-head case, but refuses to do
398 complex merge that needs manual resolution. It is
399 primarily meant to be used for bundling topic branch
400 heads together. This is the default merge strategy when
401 pulling or merging more than one branches.
402</p>
403</dd>
404<dt>
405ours
406</dt>
407<dd>
408<p>
409 This resolves any number of heads, but the result of the
410 merge is always the current branch head. It is meant to
411 be used to supersede old development history of side
412 branches.
413</p>
414</dd>
415</dl>
416<p>If you tried a merge which resulted in a complex conflicts and
417would want to start over, you can recover with
418<a href="git-reset.html">git-reset(1)</a>.</p>
419</div>
420<h2>HOW MERGE WORKS</h2>
421<div class="sectionbody">
422<p>A merge is always between the current <tt>HEAD</tt> and one or more
423remote branch heads, and the index file must exactly match the
424tree of <tt>HEAD</tt> commit (i.e. the contents of the last commit) when
425it happens. In other words, <tt>git-diff --cached HEAD</tt> must
426report no changes.</p>
427<div class="admonitionblock">
428<table><tr>
429<td class="icon">
430<div class="title">Note</div>
431</td>
432<td class="content">This is a bit of lie. In certain special cases, your index are
433allowed to be different from the tree of <tt>HEAD</tt> commit. The most
434notable case is when your <tt>HEAD</tt> commit is already ahead of what
435is being merged, in which case your index can have arbitrary
436difference from your <tt>HEAD</tt> commit. Otherwise, your index entries
437are allowed have differences from your <tt>HEAD</tt> commit that match
438the result of trivial merge (e.g. you received the same patch
439from external source to produce the same result as what you are
440merging). For example, if a path did not exist in the common
441ancestor and your head commit but exists in the tree you are
442merging into your repository, and if you already happen to have
443that path exactly in your index, the merge does not have to
444fail.</td>
445</tr></table>
446</div>
447<p>Otherwise, merge will refuse to do any harm to your repository
448(that is, it may fetch the objects from remote, and it may even
449update the local branch used to keep track of the remote branch
450with <tt>git pull remote rbranch:lbranch</tt>, but your working tree,
451<tt>.git/HEAD</tt> pointer and index file are left intact).</p>
452<p>You may have local modifications in the working tree files. In
453other words, <tt>git-diff</tt> is allowed to report changes.
454However, the merge uses your working tree as the working area,
455and in order to prevent the merge operation from losing such
456changes, it makes sure that they do not interfere with the
457merge. Those complex tables in read-tree documentation define
458what it means for a path to "interfere with the merge". And if
459your local modifications interfere with the merge, again, it
460stops before touching anything.</p>
461<p>So in the above two "failed merge" case, you do not have to
Junio C Hamano51c2ab02006-07-09 20:38:54462worry about loss of data --- you simply were not ready to do
Junio C Hamano1a4e8412005-12-27 08:17:23463a merge, so no merge happened at all. You may want to finish
464whatever you were in the middle of doing, and retry the same
465pull after you are done and ready.</p>
466<p>When things cleanly merge, these things happen:</p>
467<ol>
468<li>
469<p>
470the results are updated both in the index file and in your
471 working tree,
472</p>
473</li>
474<li>
475<p>
476index file is written out as a tree,
477</p>
478</li>
479<li>
480<p>
481the tree gets committed, and
482</p>
483</li>
484<li>
485<p>
486the <tt>HEAD</tt> pointer gets advanced.
487</p>
488</li>
489</ol>
490<p>Because of 2., we require that the original state of the index
491file to match exactly the current <tt>HEAD</tt> commit; otherwise we
492will write out your local changes already registered in your
493index file along with the merge result, which is not good.
494Because 1. involves only the paths different between your
495branch and the remote branch you are pulling from during the
496merge (which is typically a fraction of the whole tree), you can
497have local modifications in your working tree as long as they do
498not overlap with what the merge updates.</p>
499<p>When there are conflicts, these things happen:</p>
500<ol>
501<li>
502<p>
503<tt>HEAD</tt> stays the same.
504</p>
505</li>
506<li>
507<p>
508Cleanly merged paths are updated both in the index file and
509 in your working tree.
510</p>
511</li>
512<li>
513<p>
514For conflicting paths, the index file records up to three
515 versions; stage1 stores the version from the common ancestor,
516 stage2 from <tt>HEAD</tt>, and stage3 from the remote branch (you
517 can inspect the stages with <tt>git-ls-files -u</tt>). The working
518 tree files have the result of "merge" program; i.e. 3-way
519 merge result with familiar conflict markers <tt>&lt;&lt;&lt; === &gt;&gt;&gt;</tt>.
520</p>
521</li>
522<li>
523<p>
524No other changes are done. In particular, the local
525 modifications you had before you started merge will stay the
526 same and the index entries for them stay as they were,
527 i.e. matching <tt>HEAD</tt>.
528</p>
529</li>
530</ol>
531<p>After seeing a conflict, you can do two things:</p>
532<ul>
533<li>
534<p>
535Decide not to merge. The only clean-up you need are to reset
536 the index file to the <tt>HEAD</tt> commit to reverse 2. and to clean
537 up working tree changes made by 2. and 3.; <tt>git-reset</tt> can
538 be used for this.
539</p>
540</li>
541<li>
542<p>
543Resolve the conflicts. <tt>git-diff</tt> would report only the
544 conflicting paths because of the above 2. and 3.. Edit the
545 working tree files into a desirable shape, <tt>git-update-index</tt>
546 them, to make the index file contain what the merge result
547 should be, and run <tt>git-commit</tt> to commit the result.
548</p>
549</li>
550</ul>
551</div>
552<h2>SEE ALSO</h2>
553<div class="sectionbody">
554<p><a href="git-fmt-merge-msg.html">git-fmt-merge-msg(1)</a>, <a href="git-pull.html">git-pull(1)</a></p>
555</div>
556<h2>Author</h2>
557<div class="sectionbody">
558<p>Written by Junio C Hamano &lt;junkio@cox.net&gt;</p>
559</div>
560<h2>Documentation</h2>
561<div class="sectionbody">
562<p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
563</div>
564<h2>GIT</h2>
565<div class="sectionbody">
566<p>Part of the <a href="git.html">git(7)</a> suite</p>
567</div>
568<div id="footer">
569<div id="footer-text">
Junio C Hamano7ccb9fd2006-07-15 01:38:40570Last updated 15-Jul-2006 01:37:56 UTC
Junio C Hamano1a4e8412005-12-27 08:17:23571</div>
572</div>
573</body>
574</html>