Autogenerated HTML docs for v1.7.3.3-402-ga48aa
[git/jnareb-git.git] / git-merge.html
blob26452243db07051f56efc154fae9dc0ccbbb521c
1 <!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" />
6 <meta name="generator" content="AsciiDoc 8.4.5" />
7 <title>git-merge(1)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 git-merge(1) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>git-merge -
411 Join two or more development histories together
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="verseblock">
418 <div class="verseblock-content"><em>git merge</em> [-n] [--stat] [--no-commit] [--squash]
419 [-s &lt;strategy&gt;] [-X &lt;strategy-option&gt;]
420 [--[no-]rerere-autoupdate] [-m &lt;msg&gt;] &lt;commit&gt;&#8230;
421 <em>git merge</em> &lt;msg&gt; HEAD &lt;commit&gt;&#8230;</div>
422 <div class="verseblock-attribution">
423 </div></div>
424 </div>
425 <h2 id="_description">DESCRIPTION</h2>
426 <div class="sectionbody">
427 <div class="paragraph"><p>Incorporates changes from the named commits (since the time their
428 histories diverged from the current branch) into the current
429 branch. This command is used by <em>git pull</em> to incorporate changes
430 from another repository and can be used by hand to merge changes
431 from one branch into another.</p></div>
432 <div class="paragraph"><p>Assume the following history exists and the current branch is
433 "<tt>master</tt>":</p></div>
434 <div class="listingblock">
435 <div class="content">
436 <pre><tt> A---B---C topic
438 D---E---F---G master</tt></pre>
439 </div></div>
440 <div class="paragraph"><p>Then "<tt>git merge topic</tt>" will replay the changes made on the
441 <tt>topic</tt> branch since it diverged from <tt>master</tt> (i.e., <tt>E</tt>) until
442 its current commit (<tt>C</tt>) on top of <tt>master</tt>, and record the result
443 in a new commit along with the names of the two parent commits and
444 a log message from the user describing the changes.</p></div>
445 <div class="listingblock">
446 <div class="content">
447 <pre><tt> A---B---C topic
449 D---E---F---G---H master</tt></pre>
450 </div></div>
451 <div class="paragraph"><p>The second syntax (&lt;msg&gt; <tt>HEAD</tt> &lt;commit&gt;&#8230;) is supported for
452 historical reasons. Do not use it from the command line or in
453 new scripts. It is the same as <tt>git merge -m &lt;msg&gt; &lt;commit&gt;&#8230;</tt>.</p></div>
454 <div class="paragraph"><p><strong>Warning</strong>: Running <em>git merge</em> with uncommitted changes is
455 discouraged: while possible, it leaves you in a state that is hard to
456 back out of in the case of a conflict.</p></div>
457 </div>
458 <h2 id="_options">OPTIONS</h2>
459 <div class="sectionbody">
460 <div class="dlist"><dl>
461 <dt class="hdlist1">
462 --commit
463 </dt>
464 <dt class="hdlist1">
465 --no-commit
466 </dt>
467 <dd>
469 Perform the merge and commit the result. This option can
470 be used to override --no-commit.
471 </p>
472 <div class="paragraph"><p>With --no-commit perform the merge but pretend the merge
473 failed and do not autocommit, to give the user a chance to
474 inspect and further tweak the merge result before committing.</p></div>
475 </dd>
476 <dt class="hdlist1">
477 --ff
478 </dt>
479 <dt class="hdlist1">
480 --no-ff
481 </dt>
482 <dd>
484 Do not generate a merge commit if the merge resolved as
485 a fast-forward, only update the branch pointer. This is
486 the default behavior of git-merge.
487 </p>
488 <div class="paragraph"><p>With --no-ff Generate a merge commit even if the merge
489 resolved as a fast-forward.</p></div>
490 </dd>
491 <dt class="hdlist1">
492 --log[=&lt;n&gt;]
493 </dt>
494 <dt class="hdlist1">
495 --no-log
496 </dt>
497 <dd>
499 In addition to branch names, populate the log message with
500 one-line descriptions from at most &lt;n&gt; actual commits that are being
501 merged. See also <a href="git-fmt-merge-msg.html">git-fmt-merge-msg(1)</a>.
502 </p>
503 <div class="paragraph"><p>With --no-log do not list one-line descriptions from the
504 actual commits being merged.</p></div>
505 </dd>
506 <dt class="hdlist1">
507 --stat
508 </dt>
509 <dt class="hdlist1">
511 </dt>
512 <dt class="hdlist1">
513 --no-stat
514 </dt>
515 <dd>
517 Show a diffstat at the end of the merge. The diffstat is also
518 controlled by the configuration option merge.stat.
519 </p>
520 <div class="paragraph"><p>With -n or --no-stat do not show a diffstat at the end of the
521 merge.</p></div>
522 </dd>
523 <dt class="hdlist1">
524 --squash
525 </dt>
526 <dt class="hdlist1">
527 --no-squash
528 </dt>
529 <dd>
531 Produce the working tree and index state as if a real
532 merge happened (except for the merge information),
533 but do not actually make a commit or
534 move the <tt>HEAD</tt>, nor record <tt>$GIT_DIR/MERGE_HEAD</tt> to
535 cause the next <tt>git commit</tt> command to create a merge
536 commit. This allows you to create a single commit on
537 top of the current branch whose effect is the same as
538 merging another branch (or more in case of an octopus).
539 </p>
540 <div class="paragraph"><p>With --no-squash perform the merge and commit the result. This
541 option can be used to override --squash.</p></div>
542 </dd>
543 <dt class="hdlist1">
544 --ff-only
545 </dt>
546 <dd>
548 Refuse to merge and exit with a non-zero status unless the
549 current <tt>HEAD</tt> is already up-to-date or the merge can be
550 resolved as a fast-forward.
551 </p>
552 </dd>
553 <dt class="hdlist1">
554 -s &lt;strategy&gt;
555 </dt>
556 <dt class="hdlist1">
557 --strategy=&lt;strategy&gt;
558 </dt>
559 <dd>
561 Use the given merge strategy; can be supplied more than
562 once to specify them in the order they should be tried.
563 If there is no <tt>-s</tt> option, a built-in list of strategies
564 is used instead (<em>git merge-recursive</em> when merging a single
565 head, <em>git merge-octopus</em> otherwise).
566 </p>
567 </dd>
568 <dt class="hdlist1">
569 -X &lt;option&gt;
570 </dt>
571 <dt class="hdlist1">
572 --strategy-option=&lt;option&gt;
573 </dt>
574 <dd>
576 Pass merge strategy specific option through to the merge
577 strategy.
578 </p>
579 </dd>
580 <dt class="hdlist1">
581 --summary
582 </dt>
583 <dt class="hdlist1">
584 --no-summary
585 </dt>
586 <dd>
588 Synonyms to --stat and --no-stat; these are deprecated and will be
589 removed in the future.
590 </p>
591 </dd>
592 <dt class="hdlist1">
594 </dt>
595 <dt class="hdlist1">
596 --quiet
597 </dt>
598 <dd>
600 Operate quietly.
601 </p>
602 </dd>
603 <dt class="hdlist1">
605 </dt>
606 <dt class="hdlist1">
607 --verbose
608 </dt>
609 <dd>
611 Be verbose.
612 </p>
613 </dd>
614 <dt class="hdlist1">
615 -m &lt;msg&gt;
616 </dt>
617 <dd>
619 Set the commit message to be used for the merge commit (in
620 case one is created).
621 </p>
622 <div class="paragraph"><p>If <tt>--log</tt> is specified, a shortlog of the commits being merged
623 will be appended to the specified message.</p></div>
624 <div class="paragraph"><p>The <em>git fmt-merge-msg</em> command can be
625 used to give a good default for automated <em>git merge</em>
626 invocations.</p></div>
627 </dd>
628 <dt class="hdlist1">
629 --rerere-autoupdate
630 </dt>
631 <dt class="hdlist1">
632 --no-rerere-autoupdate
633 </dt>
634 <dd>
636 Allow the rerere mechanism to update the index with the
637 result of auto-conflict resolution if possible.
638 </p>
639 </dd>
640 <dt class="hdlist1">
641 &lt;commit&gt;&#8230;
642 </dt>
643 <dd>
645 Commits, usually other branch heads, to merge into our branch.
646 You need at least one &lt;commit&gt;. Specifying more than one
647 &lt;commit&gt; obviously means you are trying an Octopus.
648 </p>
649 </dd>
650 </dl></div>
651 </div>
652 <h2 id="_pre_merge_checks">PRE-MERGE CHECKS</h2>
653 <div class="sectionbody">
654 <div class="paragraph"><p>Before applying outside changes, you should get your own work in
655 good shape and committed locally, so it will not be clobbered if
656 there are conflicts. See also <a href="git-stash.html">git-stash(1)</a>.
657 <em>git pull</em> and <em>git merge</em> will stop without doing anything when
658 local uncommitted changes overlap with files that <em>git pull</em>/<em>git
659 merge</em> may need to update.</p></div>
660 <div class="paragraph"><p>To avoid recording unrelated changes in the merge commit,
661 <em>git pull</em> and <em>git merge</em> will also abort if there are any changes
662 registered in the index relative to the <tt>HEAD</tt> commit. (One
663 exception is when the changed index entries are in the state that
664 would result from the merge already.)</p></div>
665 <div class="paragraph"><p>If all named commits are already ancestors of <tt>HEAD</tt>, <em>git merge</em>
666 will exit early with the message "Already up-to-date."</p></div>
667 </div>
668 <h2 id="_fast_forward_merge">FAST-FORWARD MERGE</h2>
669 <div class="sectionbody">
670 <div class="paragraph"><p>Often the current branch head is an ancestor of the named commit.
671 This is the most common case especially when invoked from <em>git
672 pull</em>: you are tracking an upstream repository, you have committed
673 no local changes, and now you want to update to a newer upstream
674 revision. In this case, a new commit is not needed to store the
675 combined history; instead, the <tt>HEAD</tt> (along with the index) is
676 updated to point at the named commit, without creating an extra
677 merge commit.</p></div>
678 <div class="paragraph"><p>This behavior can be suppressed with the <tt>--no-ff</tt> option.</p></div>
679 </div>
680 <h2 id="_true_merge">TRUE MERGE</h2>
681 <div class="sectionbody">
682 <div class="paragraph"><p>Except in a fast-forward merge (see above), the branches to be
683 merged must be tied together by a merge commit that has both of them
684 as its parents.</p></div>
685 <div class="paragraph"><p>A merged version reconciling the changes from all branches to be
686 merged is committed, and your <tt>HEAD</tt>, index, and working tree are
687 updated to it. It is possible to have modifications in the working
688 tree as long as they do not overlap; the update will preserve them.</p></div>
689 <div class="paragraph"><p>When it is not obvious how to reconcile the changes, the following
690 happens:</p></div>
691 <div class="olist arabic"><ol class="arabic">
692 <li>
694 The <tt>HEAD</tt> pointer stays the same.
695 </p>
696 </li>
697 <li>
699 The <tt>MERGE_HEAD</tt> ref is set to point to the other branch head.
700 </p>
701 </li>
702 <li>
704 Paths that merged cleanly are updated both in the index file and
705 in your working tree.
706 </p>
707 </li>
708 <li>
710 For conflicting paths, the index file records up to three
711 versions: stage 1 stores the version from the common ancestor,
712 stage 2 from <tt>HEAD</tt>, and stage 3 from <tt>MERGE_HEAD</tt> (you
713 can inspect the stages with <tt>git ls-files -u</tt>). The working
714 tree files contain the result of the "merge" program; i.e. 3-way
715 merge results with familiar conflict markers <tt>&lt;&lt;&lt;</tt> <tt>===</tt> <tt>&gt;&gt;&gt;</tt>.
716 </p>
717 </li>
718 <li>
720 No other changes are made. In particular, the local
721 modifications you had before you started merge will stay the
722 same and the index entries for them stay as they were,
723 i.e. matching <tt>HEAD</tt>.
724 </p>
725 </li>
726 </ol></div>
727 <div class="paragraph"><p>If you tried a merge which resulted in complex conflicts and
728 want to start over, you can recover with <tt>git reset --merge</tt>.</p></div>
729 </div>
730 <h2 id="_how_conflicts_are_presented">HOW CONFLICTS ARE PRESENTED</h2>
731 <div class="sectionbody">
732 <div class="paragraph"><p>During a merge, the working tree files are updated to reflect the result
733 of the merge. Among the changes made to the common ancestor&#8217;s version,
734 non-overlapping ones (that is, you changed an area of the file while the
735 other side left that area intact, or vice versa) are incorporated in the
736 final result verbatim. When both sides made changes to the same area,
737 however, git cannot randomly pick one side over the other, and asks you to
738 resolve it by leaving what both sides did to that area.</p></div>
739 <div class="paragraph"><p>By default, git uses the same style as that is used by "merge" program
740 from the RCS suite to present such a conflicted hunk, like this:</p></div>
741 <div class="listingblock">
742 <div class="content">
743 <pre><tt>Here are lines that are either unchanged from the common
744 ancestor, or cleanly resolved because only one side changed.
745 &lt;&lt;&lt;&lt;&lt;&lt;&lt; yours:sample.txt
746 Conflict resolution is hard;
747 let's go shopping.
748 =======
749 Git makes conflict resolution easy.
750 &gt;&gt;&gt;&gt;&gt;&gt;&gt; theirs:sample.txt
751 And here is another line that is cleanly resolved or unmodified.</tt></pre>
752 </div></div>
753 <div class="paragraph"><p>The area where a pair of conflicting changes happened is marked with markers
754 <tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</tt>, <tt>=======</tt>, and <tt>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</tt>. The part before the <tt>=======</tt>
755 is typically your side, and the part afterwards is typically their side.</p></div>
756 <div class="paragraph"><p>The default format does not show what the original said in the conflicting
757 area. You cannot tell how many lines are deleted and replaced with
758 Barbie&#8217;s remark on your side. The only thing you can tell is that your
759 side wants to say it is hard and you&#8217;d prefer to go shopping, while the
760 other side wants to claim it is easy.</p></div>
761 <div class="paragraph"><p>An alternative style can be used by setting the "merge.conflictstyle"
762 configuration variable to "diff3". In "diff3" style, the above conflict
763 may look like this:</p></div>
764 <div class="listingblock">
765 <div class="content">
766 <pre><tt>Here are lines that are either unchanged from the common
767 ancestor, or cleanly resolved because only one side changed.
768 &lt;&lt;&lt;&lt;&lt;&lt;&lt; yours:sample.txt
769 Conflict resolution is hard;
770 let's go shopping.
771 |||||||
772 Conflict resolution is hard.
773 =======
774 Git makes conflict resolution easy.
775 &gt;&gt;&gt;&gt;&gt;&gt;&gt; theirs:sample.txt
776 And here is another line that is cleanly resolved or unmodified.</tt></pre>
777 </div></div>
778 <div class="paragraph"><p>In addition to the <tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</tt>, <tt>=======</tt>, and <tt>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</tt> markers, it uses
779 another <tt>|||||||</tt> marker that is followed by the original text. You can
780 tell that the original just stated a fact, and your side simply gave in to
781 that statement and gave up, while the other side tried to have a more
782 positive attitude. You can sometimes come up with a better resolution by
783 viewing the original.</p></div>
784 </div>
785 <h2 id="_how_to_resolve_conflicts">HOW TO RESOLVE CONFLICTS</h2>
786 <div class="sectionbody">
787 <div class="paragraph"><p>After seeing a conflict, you can do two things:</p></div>
788 <div class="ulist"><ul>
789 <li>
791 Decide not to merge. The only clean-ups you need are to reset
792 the index file to the <tt>HEAD</tt> commit to reverse 2. and to clean
793 up working tree changes made by 2. and 3.; <tt>git-reset --hard</tt> can
794 be used for this.
795 </p>
796 </li>
797 <li>
799 Resolve the conflicts. Git will mark the conflicts in
800 the working tree. Edit the files into shape and
801 <em>git add</em> them to the index. Use <em>git commit</em> to seal the deal.
802 </p>
803 </li>
804 </ul></div>
805 <div class="paragraph"><p>You can work through the conflict with a number of tools:</p></div>
806 <div class="ulist"><ul>
807 <li>
809 Use a mergetool. <tt>git mergetool</tt> to launch a graphical
810 mergetool which will work you through the merge.
811 </p>
812 </li>
813 <li>
815 Look at the diffs. <tt>git diff</tt> will show a three-way diff,
816 highlighting changes from both the <tt>HEAD</tt> and <tt>MERGE_HEAD</tt>
817 versions.
818 </p>
819 </li>
820 <li>
822 Look at the diffs from each branch. <tt>git log --merge -p &lt;path&gt;</tt>
823 will show diffs first for the <tt>HEAD</tt> version and then the
824 <tt>MERGE_HEAD</tt> version.
825 </p>
826 </li>
827 <li>
829 Look at the originals. <tt>git show :1:filename</tt> shows the
830 common ancestor, <tt>git show :2:filename</tt> shows the <tt>HEAD</tt>
831 version, and <tt>git show :3:filename</tt> shows the <tt>MERGE_HEAD</tt>
832 version.
833 </p>
834 </li>
835 </ul></div>
836 </div>
837 <h2 id="_examples">EXAMPLES</h2>
838 <div class="sectionbody">
839 <div class="ulist"><ul>
840 <li>
842 Merge branches <tt>fixes</tt> and <tt>enhancements</tt> on top of
843 the current branch, making an octopus merge:
844 </p>
845 <div class="listingblock">
846 <div class="content">
847 <pre><tt>$ git merge fixes enhancements</tt></pre>
848 </div></div>
849 </li>
850 <li>
852 Merge branch <tt>obsolete</tt> into the current branch, using <tt>ours</tt>
853 merge strategy:
854 </p>
855 <div class="listingblock">
856 <div class="content">
857 <pre><tt>$ git merge -s ours obsolete</tt></pre>
858 </div></div>
859 </li>
860 <li>
862 Merge branch <tt>maint</tt> into the current branch, but do not make
863 a new commit automatically:
864 </p>
865 <div class="listingblock">
866 <div class="content">
867 <pre><tt>$ git merge --no-commit maint</tt></pre>
868 </div></div>
869 <div class="paragraph"><p>This can be used when you want to include further changes to the
870 merge, or want to write your own merge commit message.</p></div>
871 <div class="paragraph"><p>You should refrain from abusing this option to sneak substantial
872 changes into a merge commit. Small fixups like bumping
873 release/version name would be acceptable.</p></div>
874 </li>
875 </ul></div>
876 </div>
877 <h2 id="_merge_strategies">MERGE STRATEGIES</h2>
878 <div class="sectionbody">
879 <div class="paragraph"><p>The merge mechanism (<em>git-merge</em> and <em>git-pull</em> commands) allows the
880 backend <em>merge strategies</em> to be chosen with <tt>-s</tt> option. Some strategies
881 can also take their own options, which can be passed by giving <tt>-X&lt;option&gt;</tt>
882 arguments to <em>git-merge</em> and/or <em>git-pull</em>.</p></div>
883 <div class="dlist"><dl>
884 <dt class="hdlist1">
885 resolve
886 </dt>
887 <dd>
889 This can only resolve two heads (i.e. the current branch
890 and another branch you pulled from) using a 3-way merge
891 algorithm. It tries to carefully detect criss-cross
892 merge ambiguities and is considered generally safe and
893 fast.
894 </p>
895 </dd>
896 <dt class="hdlist1">
897 recursive
898 </dt>
899 <dd>
901 This can only resolve two heads using a 3-way merge
902 algorithm. When there is more than one common
903 ancestor that can be used for 3-way merge, it creates a
904 merged tree of the common ancestors and uses that as
905 the reference tree for the 3-way merge. This has been
906 reported to result in fewer merge conflicts without
907 causing mis-merges by tests done on actual merge commits
908 taken from Linux 2.6 kernel development history.
909 Additionally this can detect and handle merges involving
910 renames. This is the default merge strategy when
911 pulling or merging one branch.
912 </p>
913 <div class="paragraph"><p>The <em>recursive</em> strategy can take the following options:</p></div>
914 <div class="dlist"><dl>
915 <dt class="hdlist1">
916 ours
917 </dt>
918 <dd>
920 This option forces conflicting hunks to be auto-resolved cleanly by
921 favoring <em>our</em> version. Changes from the other tree that do not
922 conflict with our side are reflected to the merge result.
923 </p>
924 <div class="paragraph"><p>This should not be confused with the <em>ours</em> merge strategy, which does not
925 even look at what the other tree contains at all. It discards everything
926 the other tree did, declaring <em>our</em> history contains all that happened in it.</p></div>
927 </dd>
928 <dt class="hdlist1">
929 theirs
930 </dt>
931 <dd>
933 This is opposite of <em>ours</em>.
934 </p>
935 </dd>
936 <dt class="hdlist1">
937 patience
938 </dt>
939 <dd>
941 With this option, <em>merge-recursive</em> spends a little extra time
942 to avoid mismerges that sometimes occur due to unimportant
943 matching lines (e.g., braces from distinct functions). Use
944 this when the branches to be merged have diverged wildly.
945 See also <a href="git-diff.html">git-diff(1)</a> <tt>--patience</tt>.
946 </p>
947 </dd>
948 <dt class="hdlist1">
949 ignore-space-change
950 </dt>
951 <dt class="hdlist1">
952 ignore-all-space
953 </dt>
954 <dt class="hdlist1">
955 ignore-space-at-eol
956 </dt>
957 <dd>
959 Treats lines with the indicated type of whitespace change as
960 unchanged for the sake of a three-way merge. Whitespace
961 changes mixed with other changes to a line are not ignored.
962 See also <a href="git-diff.html">git-diff(1)</a> <tt>-b</tt>, <tt>-w</tt>, and
963 <tt>--ignore-space-at-eol</tt>.
964 </p>
965 <div class="ulist"><ul>
966 <li>
968 If <em>their</em> version only introduces whitespace changes to a line,
969 <em>our</em> version is used;
970 </p>
971 </li>
972 <li>
974 If <em>our</em> version introduces whitespace changes but <em>their</em>
975 version includes a substantial change, <em>their</em> version is used;
976 </p>
977 </li>
978 <li>
980 Otherwise, the merge proceeds in the usual way.
981 </p>
982 </li>
983 </ul></div>
984 </dd>
985 <dt class="hdlist1">
986 renormalize
987 </dt>
988 <dd>
990 This runs a virtual check-out and check-in of all three stages
991 of a file when resolving a three-way merge. This option is
992 meant to be used when merging branches with different clean
993 filters or end-of-line normalization rules. See "Merging
994 branches with differing checkin/checkout attributes" in
995 <a href="gitattributes.html">gitattributes(5)</a> for details.
996 </p>
997 </dd>
998 <dt class="hdlist1">
999 no-renormalize
1000 </dt>
1001 <dd>
1003 Disables the <tt>renormalize</tt> option. This overrides the
1004 <tt>merge.renormalize</tt> configuration variable.
1005 </p>
1006 </dd>
1007 <dt class="hdlist1">
1008 rename-threshold=&lt;n&gt;
1009 </dt>
1010 <dd>
1012 Controls the similarity threshold used for rename detection.
1013 See also <a href="git-diff.html">git-diff(1)</a> <tt>-M</tt>.
1014 </p>
1015 </dd>
1016 <dt class="hdlist1">
1017 subtree[=&lt;path&gt;]
1018 </dt>
1019 <dd>
1021 This option is a more advanced form of <em>subtree</em> strategy, where
1022 the strategy makes a guess on how two trees must be shifted to
1023 match with each other when merging. Instead, the specified path
1024 is prefixed (or stripped from the beginning) to make the shape of
1025 two trees to match.
1026 </p>
1027 </dd>
1028 </dl></div>
1029 </dd>
1030 <dt class="hdlist1">
1031 octopus
1032 </dt>
1033 <dd>
1035 This resolves cases with more than two heads, but refuses to do
1036 a complex merge that needs manual resolution. It is
1037 primarily meant to be used for bundling topic branch
1038 heads together. This is the default merge strategy when
1039 pulling or merging more than one branch.
1040 </p>
1041 </dd>
1042 <dt class="hdlist1">
1043 ours
1044 </dt>
1045 <dd>
1047 This resolves any number of heads, but the resulting tree of the
1048 merge is always that of the current branch head, effectively
1049 ignoring all changes from all other branches. It is meant to
1050 be used to supersede old development history of side
1051 branches. Note that this is different from the -Xours option to
1052 the <em>recursive</em> merge strategy.
1053 </p>
1054 </dd>
1055 <dt class="hdlist1">
1056 subtree
1057 </dt>
1058 <dd>
1060 This is a modified recursive strategy. When merging trees A and
1061 B, if B corresponds to a subtree of A, B is first adjusted to
1062 match the tree structure of A, instead of reading the trees at
1063 the same level. This adjustment is also done to the common
1064 ancestor tree.
1065 </p>
1066 </dd>
1067 </dl></div>
1068 </div>
1069 <h2 id="_configuration">CONFIGURATION</h2>
1070 <div class="sectionbody">
1071 <div class="dlist"><dl>
1072 <dt class="hdlist1">
1073 merge.conflictstyle
1074 </dt>
1075 <dd>
1077 Specify the style in which conflicted hunks are written out to
1078 working tree files upon merge. The default is "merge", which
1079 shows a <tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt;</tt> conflict marker, changes made by one side,
1080 a <tt>=======</tt> marker, changes made by the other side, and then
1081 a <tt>&gt;&gt;&gt;&gt;&gt;&gt;&gt;</tt> marker. An alternate style, "diff3", adds a <tt>|||||||</tt>
1082 marker and the original text before the <tt>=======</tt> marker.
1083 </p>
1084 </dd>
1085 <dt class="hdlist1">
1086 merge.log
1087 </dt>
1088 <dd>
1090 In addition to branch names, populate the log message with at
1091 most the specified number of one-line descriptions from the
1092 actual commits that are being merged. Defaults to false, and
1093 true is a synoym for 20.
1094 </p>
1095 </dd>
1096 <dt class="hdlist1">
1097 merge.renameLimit
1098 </dt>
1099 <dd>
1101 The number of files to consider when performing rename detection
1102 during a merge; if not specified, defaults to the value of
1103 diff.renameLimit.
1104 </p>
1105 </dd>
1106 <dt class="hdlist1">
1107 merge.renormalize
1108 </dt>
1109 <dd>
1111 Tell git that canonical representation of files in the
1112 repository has changed over time (e.g. earlier commits record
1113 text files with CRLF line endings, but recent ones use LF line
1114 endings). In such a repository, git can convert the data
1115 recorded in commits to a canonical form before performing a
1116 merge to reduce unnecessary conflicts. For more information,
1117 see section "Merging branches with differing checkin/checkout
1118 attributes" in <a href="gitattributes.html">gitattributes(5)</a>.
1119 </p>
1120 </dd>
1121 <dt class="hdlist1">
1122 merge.stat
1123 </dt>
1124 <dd>
1126 Whether to print the diffstat between ORIG_HEAD and the merge result
1127 at the end of the merge. True by default.
1128 </p>
1129 </dd>
1130 <dt class="hdlist1">
1131 merge.tool
1132 </dt>
1133 <dd>
1135 Controls which merge resolution program is used by
1136 <a href="git-mergetool.html">git-mergetool(1)</a>. Valid built-in values are: "kdiff3",
1137 "tkdiff", "meld", "xxdiff", "emerge", "vimdiff", "gvimdiff",
1138 "diffuse", "ecmerge", "tortoisemerge", "p4merge", "araxis" and
1139 "opendiff". Any other value is treated is custom merge tool
1140 and there must be a corresponding mergetool.&lt;tool&gt;.cmd option.
1141 </p>
1142 </dd>
1143 <dt class="hdlist1">
1144 merge.verbosity
1145 </dt>
1146 <dd>
1148 Controls the amount of output shown by the recursive merge
1149 strategy. Level 0 outputs nothing except a final error
1150 message if conflicts were detected. Level 1 outputs only
1151 conflicts, 2 outputs conflicts and file changes. Level 5 and
1152 above outputs debugging information. The default is level 2.
1153 Can be overridden by the <em>GIT_MERGE_VERBOSITY</em> environment variable.
1154 </p>
1155 </dd>
1156 <dt class="hdlist1">
1157 merge.&lt;driver&gt;.name
1158 </dt>
1159 <dd>
1161 Defines a human-readable name for a custom low-level
1162 merge driver. See <a href="gitattributes.html">gitattributes(5)</a> for details.
1163 </p>
1164 </dd>
1165 <dt class="hdlist1">
1166 merge.&lt;driver&gt;.driver
1167 </dt>
1168 <dd>
1170 Defines the command that implements a custom low-level
1171 merge driver. See <a href="gitattributes.html">gitattributes(5)</a> for details.
1172 </p>
1173 </dd>
1174 <dt class="hdlist1">
1175 merge.&lt;driver&gt;.recursive
1176 </dt>
1177 <dd>
1179 Names a low-level merge driver to be used when
1180 performing an internal merge between common ancestors.
1181 See <a href="gitattributes.html">gitattributes(5)</a> for details.
1182 </p>
1183 </dd>
1184 <dt class="hdlist1">
1185 branch.&lt;name&gt;.mergeoptions
1186 </dt>
1187 <dd>
1189 Sets default options for merging into branch &lt;name&gt;. The syntax and
1190 supported options are the same as those of <em>git merge</em>, but option
1191 values containing whitespace characters are currently not supported.
1192 </p>
1193 </dd>
1194 </dl></div>
1195 </div>
1196 <h2 id="_see_also">SEE ALSO</h2>
1197 <div class="sectionbody">
1198 <div class="paragraph"><p><a href="git-fmt-merge-msg.html">git-fmt-merge-msg(1)</a>, <a href="git-pull.html">git-pull(1)</a>,
1199 <a href="gitattributes.html">gitattributes(5)</a>,
1200 <a href="git-reset.html">git-reset(1)</a>,
1201 <a href="git-diff.html">git-diff(1)</a>, <a href="git-ls-files.html">git-ls-files(1)</a>,
1202 <a href="git-add.html">git-add(1)</a>, <a href="git-rm.html">git-rm(1)</a>,
1203 <a href="git-mergetool.html">git-mergetool(1)</a></p></div>
1204 </div>
1205 <h2 id="_author">Author</h2>
1206 <div class="sectionbody">
1207 <div class="paragraph"><p>Written by Junio C Hamano &lt;<a href="mailto:gitster@pobox.com">gitster@pobox.com</a>&gt;</p></div>
1208 </div>
1209 <h2 id="_documentation">Documentation</h2>
1210 <div class="sectionbody">
1211 <div class="paragraph"><p>Documentation by Junio C Hamano and the git-list &lt;<a href="mailto:git@vger.kernel.org">git@vger.kernel.org</a>&gt;.</p></div>
1212 </div>
1213 <h2 id="_git">GIT</h2>
1214 <div class="sectionbody">
1215 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1216 </div>
1217 <div id="footer">
1218 <div id="footer-text">
1219 Last updated 2010-11-06 00:41:57 UTC
1220 </div>
1221 </div>
1222 </body>
1223 </html>