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">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.2.5" />
7 <style type=
"text/css">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
66 border: 1px solid silver
;
81 font-family: sans-serif
;
88 font-family: sans-serif
;
92 font-family: sans-serif
;
94 border-top: 2px solid silver
;
100 padding-bottom: 0.5em;
104 padding-bottom: 0.5em;
108 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
109 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
110 div
.admonitionblock
{
113 margin-bottom: 1.5em;
115 div
.admonitionblock
{
117 margin-bottom: 2.5em;
120 div
.content
{ /* Block element content. */
124 /* Block element titles. */
125 div
.title
, caption
.title
{
126 font-family: sans-serif
;
130 margin-bottom: 0.5em;
136 td div
.title:first-child
{
139 div
.content div
.title:first-child
{
142 div
.content
+ div
.title
{
146 div
.sidebarblock
> div
.content
{
148 border: 1px solid silver
;
155 div
.listingblock
> div
.content
{
156 border: 1px solid silver
;
161 div
.quoteblock
> div
.content
{
168 div
.verseblock
+ div
.attribution
{
172 div
.admonitionblock
.icon
{
176 text-decoration: underline
;
178 padding-right: 0.5em;
180 div
.admonitionblock td
.content
{
182 border-left: 2px solid silver
;
185 div
.exampleblock
> div
.content
{
186 border-left: 2px solid silver
;
190 div
.verseblock div
.content
{
194 div
.imageblock div
.content
{ padding-left: 0; }
195 div
.imageblock img
{ border: 1px solid silver
; }
196 span
.image img
{ border-style: none
; }
200 margin-bottom: 0.8em;
212 list-style-position: outside
;
215 list-style-type: lower-alpha
;
218 div
.tableblock
> table
{
219 border: 3px solid
#527bbd;
222 font-family: sans-serif
;
231 margin-bottom: 0.8em;
239 padding-right: 0.8em;
246 div#footer-badges
{ display: none
; }
251 font-family: sans-serif
;
255 margin-bottom: 0.1em;
258 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
274 include1::./stylesheets
/xhtml11-manpage
.css
[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div
.sidebar-content
{
279 border: 1px solid silver
;
282 div
.sidebar-title
, div
.image-title
{
283 font-family: sans-serif
;
286 margin-bottom: 0.5em;
289 div
.listingblock div
.content
{
290 border: 1px solid silver
;
295 div
.quoteblock-content
{
299 div
.exampleblock-content
{
300 border-left: 2px solid silver
;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc
a:visited
{ color: blue
; }
307 <title>git-merge(
1)
</title>
312 git-merge(
1) Manual Page
315 <div class=
"sectionbody">
317 Join two or more development histories together
322 <div class=
"sectionbody">
323 <div class=
"verseblock">
324 <div class=
"content"><em>git merge
</em> [-n] [--stat] [--no-commit] [--squash] [-s
<strategy
>]
…
325 [-m
<msg
>]
<remote
>…
326 <em>git merge
</em> <msg
> HEAD
<remote
>…</div></div>
328 <h2 id=
"_description">DESCRIPTION
</h2>
329 <div class=
"sectionbody">
330 <div class=
"para"><p>This is the top-level interface to the merge machinery
331 which drives multiple merge strategy scripts.
</p></div>
332 <div class=
"para"><p>The second syntax (
<msg
> <tt>HEAD
</tt> <remote
>) is supported for
333 historical reasons. Do not use it from the command line or in
334 new scripts. It is the same as
<tt>git merge -m
<msg
> <remote
></tt>.
</p></div>
336 <h2 id=
"_options">OPTIONS
</h2>
337 <div class=
"sectionbody">
338 <div class=
"vlist"><dl>
366 Show a diffstat at the end of the merge. The diffstat is also
367 controlled by the configuration option merge.stat.
378 Do not show a diffstat at the end of the merge.
389 Synonyms to --stat and --no-stat; these are deprecated and will be
390 removed in the future.
398 In addition to branch names, populate the log message with
399 one-line descriptions from the actual commits that are being
408 Do not list one-line descriptions from the actual commits being
417 Perform the merge but pretend the merge failed and do
418 not autocommit, to give the user a chance to inspect and
419 further tweak the merge result before committing.
427 Perform the merge and commit the result. This option can
428 be used to override --no-commit.
436 Produce the working tree and index state as if a real
437 merge happened (except for the merge information),
438 but do not actually make a commit or
439 move the
<tt>HEAD
</tt>, nor record
<tt>$GIT_DIR/MERGE_HEAD
</tt> to
440 cause the next
<tt>git commit
</tt> command to create a merge
441 commit. This allows you to create a single commit on
442 top of the current branch whose effect is the same as
443 merging another branch (or more in case of an octopus).
451 Perform the merge and commit the result. This option can
452 be used to override --squash.
460 Generate a merge commit even if the merge resolved as a
469 Do not generate a merge commit if the merge resolved as
470 a fast-forward, only update the branch pointer. This is
471 the default behavior of git-merge.
478 --strategy=
<strategy
>
482 Use the given merge strategy; can be supplied more than
483 once to specify them in the order they should be tried.
484 If there is no
<tt>-s
</tt> option, a built-in list of strategies
485 is used instead (
<em>git-merge-recursive
</em> when merging a single
486 head,
<em>git-merge-octopus
</em> otherwise).
494 Set the commit message to be used for the merge commit (in
495 case one is created). The
<em>git fmt-merge-msg
</em> command can be
496 used to give a good default for automated
<em>git merge
</em>
501 <remote
>…
505 Other branch heads to merge into our branch. You need at
506 least one
<remote
>. Specifying more than one
<remote
>
507 obviously means you are trying an Octopus.
512 <h2 id=
"_merge_strategies">MERGE STRATEGIES
</h2>
513 <div class=
"sectionbody">
514 <div class=
"vlist"><dl>
520 This can only resolve two heads (i.e. the current branch
521 and another branch you pulled from) using a
3-way merge
522 algorithm. It tries to carefully detect criss-cross
523 merge ambiguities and is considered generally safe and
532 This can only resolve two heads using a
3-way merge
533 algorithm. When there is more than one common
534 ancestor that can be used for
3-way merge, it creates a
535 merged tree of the common ancestors and uses that as
536 the reference tree for the
3-way merge. This has been
537 reported to result in fewer merge conflicts without
538 causing mis-merges by tests done on actual merge commits
539 taken from Linux
2.6 kernel development history.
540 Additionally this can detect and handle merges involving
541 renames. This is the default merge strategy when
542 pulling or merging one branch.
550 This resolves cases with more than two heads, but refuses to do
551 a complex merge that needs manual resolution. It is
552 primarily meant to be used for bundling topic branch
553 heads together. This is the default merge strategy when
554 pulling or merging more than one branch.
562 This resolves any number of heads, but the result of the
563 merge is always the current branch head. It is meant to
564 be used to supersede old development history of side
573 This is a modified recursive strategy. When merging trees A and
574 B, if B corresponds to a subtree of A, B is first adjusted to
575 match the tree structure of A, instead of reading the trees at
576 the same level. This adjustment is also done to the common
581 <div class=
"para"><p>If you tried a merge which resulted in complex conflicts and
582 want to start over, you can recover with
<em>git-reset
</em>.
</p></div>
584 <h2 id=
"_configuration">CONFIGURATION
</h2>
585 <div class=
"sectionbody">
586 <div class=
"vlist"><dl>
592 Specify the style in which conflicted hunks are written out to
593 working tree files upon merge. The default is
"merge", which
594 shows a
<tt><<<<<<<</tt> conflict marker, changes made by one side,
595 a
<tt>=======
</tt> marker, changes made by the other side, and then
596 a
<tt>>>>>>>></tt> marker. An alternate style,
"diff3", adds a
<tt>|||||||
</tt>
597 marker and the original text before the
<tt>=======
</tt> marker.
605 Whether to include summaries of merged commits in newly created
606 merge commit messages. False by default.
614 The number of files to consider when performing rename detection
615 during a merge; if not specified, defaults to the value of
624 Whether to print the diffstat between ORIG_HEAD and the merge result
625 at the end of the merge. True by default.
633 Controls which merge resolution program is used by
634 <a href=
"git-mergetool.html">git-mergetool(
1)
</a>. Valid built-in values are:
"kdiff3",
635 "tkdiff",
"meld",
"xxdiff",
"emerge",
"vimdiff",
"gvimdiff",
636 "diffuse",
"ecmerge",
"tortoisemerge",
"araxis", and
637 "opendiff". Any other value is treated is custom merge tool
638 and there must be a corresponding mergetool.
<tool
>.cmd option.
646 Controls the amount of output shown by the recursive merge
647 strategy. Level
0 outputs nothing except a final error
648 message if conflicts were detected. Level
1 outputs only
649 conflicts,
2 outputs conflicts and file changes. Level
5 and
650 above outputs debugging information. The default is level
2.
651 Can be overridden by the
<em>GIT_MERGE_VERBOSITY
</em> environment variable.
655 merge.
<driver
>.name
659 Defines a human-readable name for a custom low-level
660 merge driver. See
<a href=
"gitattributes.html">gitattributes(
5)
</a> for details.
664 merge.
<driver
>.driver
668 Defines the command that implements a custom low-level
669 merge driver. See
<a href=
"gitattributes.html">gitattributes(
5)
</a> for details.
673 merge.
<driver
>.recursive
677 Names a low-level merge driver to be used when
678 performing an internal merge between common ancestors.
679 See
<a href=
"gitattributes.html">gitattributes(
5)
</a> for details.
683 branch.
<name
>.mergeoptions
687 Sets default options for merging into branch
<name
>. The syntax and
688 supported options are the same as those of
<em>git merge
</em>, but option
689 values containing whitespace characters are currently not supported.
694 <h2 id=
"_how_merge_works">HOW MERGE WORKS
</h2>
695 <div class=
"sectionbody">
696 <div class=
"para"><p>A merge is always between the current
<tt>HEAD
</tt> and one or more
697 commits (usually, branch head or tag), and the index file must
698 match the tree of
<tt>HEAD
</tt> commit (i.e. the contents of the last commit)
699 when it starts out. In other words,
<tt>git diff --cached HEAD
</tt> must
700 report no changes. (One exception is when the changed index
701 entries are already in the same state that would result from
702 the merge anyway.)
</p></div>
703 <div class=
"para"><p>Three kinds of merge can happen:
</p></div>
704 <div class=
"ilist"><ul>
707 The merged commit is already contained in
<tt>HEAD
</tt>. This is the
708 simplest case, called
"Already up-to-date."
713 <tt>HEAD
</tt> is already contained in the merged commit. This is the
714 most common case especially when invoked from
<em>git pull
</em>:
715 you are tracking an upstream repository, have committed no local
716 changes and now you want to update to a newer upstream revision.
717 Your
<tt>HEAD
</tt> (and the index) is updated to point at the merged
718 commit, without creating an extra merge commit. This is
719 called
"Fast-forward".
724 Both the merged commit and
<tt>HEAD
</tt> are independent and must be
725 tied together by a merge commit that has both of them as its parents.
726 The rest of this section describes this
"True merge" case.
730 <div class=
"para"><p>The chosen merge strategy merges the two commits into a single
732 When things merge cleanly, this is what happens:
</p></div>
733 <div class=
"olist"><ol>
736 The results are updated both in the index file and in your
742 Index file is written out as a tree;
747 The tree gets committed; and
752 The
<tt>HEAD
</tt> pointer gets advanced.
756 <div class=
"para"><p>Because of
2., we require that the original state of the index
757 file matches exactly the current
<tt>HEAD
</tt> commit; otherwise we
758 will write out your local changes already registered in your
759 index file along with the merge result, which is not good.
760 Because
1. involves only those paths differing between your
761 branch and the remote branch you are pulling from during the
762 merge (which is typically a fraction of the whole tree), you can
763 have local modifications in your working tree as long as they do
764 not overlap with what the merge updates.
</p></div>
765 <div class=
"para"><p>When there are conflicts, the following happens:
</p></div>
766 <div class=
"olist"><ol>
769 <tt>HEAD
</tt> stays the same.
774 Cleanly merged paths are updated both in the index file and
775 in your working tree.
780 For conflicting paths, the index file records up to three
781 versions; stage1 stores the version from the common ancestor,
782 stage2 from
<tt>HEAD
</tt>, and stage3 from the remote branch (you
783 can inspect the stages with
<tt>git ls-files -u
</tt>). The working
784 tree files contain the result of the
"merge" program; i.e.
3-way
785 merge results with familiar conflict markers
<tt><<< ===
>>></tt>.
790 No other changes are done. In particular, the local
791 modifications you had before you started merge will stay the
792 same and the index entries for them stay as they were,
793 i.e. matching
<tt>HEAD
</tt>.
798 <h2 id=
"_how_conflicts_are_presented">HOW CONFLICTS ARE PRESENTED
</h2>
799 <div class=
"sectionbody">
800 <div class=
"para"><p>During a merge, the working tree files are updated to reflect the result
801 of the merge. Among the changes made to the common ancestor's version,
802 non-overlapping ones (that is, you changed an area of the file while the
803 other side left that area intact, or vice versa) are incorporated in the
804 final result verbatim. When both sides made changes to the same area,
805 however, git cannot randomly pick one side over the other, and asks you to
806 resolve it by leaving what both sides did to that area.
</p></div>
807 <div class=
"para"><p>By default, git uses the same style as that is used by
"merge" program
808 from the RCS suite to present such a conflicted hunk, like this:
</p></div>
809 <div class=
"listingblock">
810 <div class=
"content">
811 <pre><tt>Here are lines that are either unchanged from the common
812 ancestor, or cleanly resolved because only one side changed.
813 <<<<<<< yours:sample.txt
814 Conflict resolution is hard;
817 Git makes conflict resolution easy.
818 >>>>>>> theirs:sample.txt
819 And here is another line that is cleanly resolved or unmodified.
</tt></pre>
821 <div class=
"para"><p>The area where a pair of conflicting changes happened is marked with markers
822 <tt><<<<<<<</tt>,
<tt>=======
</tt>, and
<tt>>>>>>>></tt>. The part before the
<tt>=======
</tt>
823 is typically your side, and the part afterwards is typically their side.
</p></div>
824 <div class=
"para"><p>The default format does not show what the original said in the conflicting
825 area. You cannot tell how many lines are deleted and replaced with
826 Barbie's remark on your side. The only thing you can tell is that your
827 side wants to say it is hard and you'd prefer to go shopping, while the
828 other side wants to claim it is easy.
</p></div>
829 <div class=
"para"><p>An alternative style can be used by setting the
"merge.conflictstyle"
830 configuration variable to
"diff3". In
"diff3" style, the above conflict
831 may look like this:
</p></div>
832 <div class=
"listingblock">
833 <div class=
"content">
834 <pre><tt>Here are lines that are either unchanged from the common
835 ancestor, or cleanly resolved because only one side changed.
836 <<<<<<< yours:sample.txt
837 Conflict resolution is hard;
840 Conflict resolution is hard.
842 Git makes conflict resolution easy.
843 >>>>>>> theirs:sample.txt
844 And here is another line that is cleanly resolved or unmodified.
</tt></pre>
846 <div class=
"para"><p>In addition to the
<tt><<<<<<<</tt>,
<tt>=======
</tt>, and
<tt>>>>>>>></tt> markers, it uses
847 another
<tt>|||||||
</tt> marker that is followed by the original text. You can
848 tell that the original just stated a fact, and your side simply gave in to
849 that statement and gave up, while the other side tried to have a more
850 positive attitude. You can sometimes come up with a better resolution by
851 viewing the original.
</p></div>
853 <h2 id=
"_how_to_resolve_conflicts">HOW TO RESOLVE CONFLICTS
</h2>
854 <div class=
"sectionbody">
855 <div class=
"para"><p>After seeing a conflict, you can do two things:
</p></div>
856 <div class=
"ilist"><ul>
859 Decide not to merge. The only clean-ups you need are to reset
860 the index file to the
<tt>HEAD
</tt> commit to reverse
2. and to clean
861 up working tree changes made by
2. and
3.;
<em>git-reset --hard
</em> can
867 Resolve the conflicts. Git will mark the conflicts in
868 the working tree. Edit the files into shape and
869 <em>git-add
</em> them to the index. Use
<em>git-commit
</em> to seal the deal.
873 <div class=
"para"><p>You can work through the conflict with a number of tools:
</p></div>
874 <div class=
"ilist"><ul>
877 Use a mergetool.
<em>git mergetool
</em> to launch a graphical
878 mergetool which will work you through the merge.
883 Look at the diffs.
<em>git diff
</em> will show a three-way diff,
884 highlighting changes from both the HEAD and remote versions.
889 Look at the diffs on their own.
<em>git log --merge -p
<path
></em>
890 will show diffs first for the HEAD version and then the
896 Look at the originals.
<em>git show :
1:filename
</em> shows the
897 common ancestor,
<em>git show :
2:filename
</em> shows the HEAD
898 version and
<em>git show :
3:filename
</em> shows the remote version.
903 <h2 id=
"_see_also">SEE ALSO
</h2>
904 <div class=
"sectionbody">
905 <div class=
"para"><p><a href=
"git-fmt-merge-msg.html">git-fmt-merge-msg(
1)
</a>,
<a href=
"git-pull.html">git-pull(
1)
</a>,
906 <a href=
"gitattributes.html">gitattributes(
5)
</a>,
907 <a href=
"git-reset.html">git-reset(
1)
</a>,
908 <a href=
"git-diff.html">git-diff(
1)
</a>,
<a href=
"git-ls-files.html">git-ls-files(
1)
</a>,
909 <a href=
"git-add.html">git-add(
1)
</a>,
<a href=
"git-rm.html">git-rm(
1)
</a>,
910 <a href=
"git-mergetool.html">git-mergetool(
1)
</a></p></div>
912 <h2 id=
"_author">Author
</h2>
913 <div class=
"sectionbody">
914 <div class=
"para"><p>Written by Junio C Hamano
<gitster@pobox.com
></p></div>
916 <h2 id=
"_documentation">Documentation
</h2>
917 <div class=
"sectionbody">
918 <div class=
"para"><p>Documentation by Junio C Hamano and the git-list
<git@vger.kernel.org
>.
</p></div>
920 <h2 id=
"_git">GIT
</h2>
921 <div class=
"sectionbody">
922 <div class=
"para"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
925 <div id=
"footer-text">
926 Last updated
2009-
10-
10 00:
56:
05 UTC