1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
\r
4 <article lang="en" id="git-merge(1)">
\r
6 <title>git-merge(1)</title>
\r
8 <primary>git-merge(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-merge - Join two or more development histories together</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git merge</emphasis> [-n] [--stat] [--no-commit] [--squash] [-s <strategy>]…
\r
19 [-m <msg>] <remote> <remote>…
\r
20 <emphasis>git merge</emphasis> <msg> HEAD <remote>…</literallayout>
\r
23 <simplesect id="_description">
\r
24 <title>DESCRIPTION</title>
\r
25 <simpara>This is the top-level interface to the merge machinery
\r
26 which drives multiple merge strategy scripts.</simpara>
\r
27 <simpara>The second syntax (<msg> <literal>HEAD</literal> <remote>) is supported for
\r
28 historical reasons. Do not use it from the command line or in
\r
29 new scripts. It is the same as <literal>git merge -m <msg> <remote></literal>.</simpara>
\r
31 <simplesect id="_options">
\r
32 <title>OPTIONS</title>
\r
66 Show a diffstat at the end of the merge. The diffstat is also
\r
67 controlled by the configuration option merge.stat.
\r
80 Do not show a diffstat at the end of the merge.
\r
93 Synonyms to --stat and --no-stat; these are deprecated and will be
\r
94 removed in the future.
\r
104 In addition to branch names, populate the log message with
\r
105 one-line descriptions from the actual commits that are being
\r
116 Do not list one-line descriptions from the actual commits being
\r
127 Perform the merge but pretend the merge failed and do
\r
128 not autocommit, to give the user a chance to inspect and
\r
129 further tweak the merge result before committing.
\r
139 Perform the merge and commit the result. This option can
\r
140 be used to override --no-commit.
\r
150 Produce the working tree and index state as if a real
\r
151 merge happened, but do not actually make a commit or
\r
152 move the <literal>HEAD</literal>, nor record <literal>$GIT_DIR/MERGE_HEAD</literal> to
\r
153 cause the next <literal>git commit</literal> command to create a merge
\r
154 commit. This allows you to create a single commit on
\r
155 top of the current branch whose effect is the same as
\r
156 merging another branch (or more in case of an octopus).
\r
166 Perform the merge and commit the result. This option can
\r
167 be used to override --squash.
\r
177 Generate a merge commit even if the merge resolved as a
\r
188 Do not generate a merge commit if the merge resolved as
\r
189 a fast-forward, only update the branch pointer. This is
\r
190 the default behavior of git-merge.
\r
196 -s <strategy>
\r
199 --strategy=<strategy>
\r
203 Use the given merge strategy; can be supplied more than
\r
204 once to specify them in the order they should be tried.
\r
205 If there is no <literal>-s</literal> option, a built-in list of strategies
\r
206 is used instead (<emphasis>git-merge-recursive</emphasis> when merging a single
\r
207 head, <emphasis>git-merge-octopus</emphasis> otherwise).
\r
217 The commit message to be used for the merge commit (in case
\r
218 it is created). The <emphasis>git-fmt-merge-msg</emphasis> script can be used
\r
219 to give a good default for automated <emphasis>git-merge</emphasis> invocations.
\r
225 <remote>…
\r
229 Other branch heads to merge into our branch. You need at
\r
230 least one <remote>. Specifying more than one <remote>
\r
231 obviously means you are trying an Octopus.
\r
237 <simplesect id="_merge_strategies">
\r
238 <title>MERGE STRATEGIES</title>
\r
246 This can only resolve two heads (i.e. the current branch
\r
247 and another branch you pulled from) using 3-way merge
\r
248 algorithm. It tries to carefully detect criss-cross
\r
249 merge ambiguities and is considered generally safe and
\r
260 This can only resolve two heads using 3-way merge
\r
261 algorithm. When there are more than one common
\r
262 ancestors that can be used for 3-way merge, it creates a
\r
263 merged tree of the common ancestors and uses that as
\r
264 the reference tree for the 3-way merge. This has been
\r
265 reported to result in fewer merge conflicts without
\r
266 causing mis-merges by tests done on actual merge commits
\r
267 taken from Linux 2.6 kernel development history.
\r
268 Additionally this can detect and handle merges involving
\r
269 renames. This is the default merge strategy when
\r
270 pulling or merging one branch.
\r
280 This resolves more than two-head case, but refuses to do
\r
281 complex merge that needs manual resolution. It is
\r
282 primarily meant to be used for bundling topic branch
\r
283 heads together. This is the default merge strategy when
\r
284 pulling or merging more than one branches.
\r
294 This resolves any number of heads, but the result of the
\r
295 merge is always the current branch head. It is meant to
\r
296 be used to supersede old development history of side
\r
307 This is a modified recursive strategy. When merging trees A and
\r
308 B, if B corresponds to a subtree of A, B is first adjusted to
\r
309 match the tree structure of A, instead of reading the trees at
\r
310 the same level. This adjustment is also done to the common
\r
316 <simpara>If you tried a merge which resulted in a complex conflicts and
\r
317 would want to start over, you can recover with <emphasis>git-reset</emphasis>.</simpara>
\r
319 <simplesect id="_configuration">
\r
320 <title>CONFIGURATION</title>
\r
324 merge.conflictstyle
\r
328 Specify the style in which conflicted hunks are written out to
\r
329 working tree files upon merge. The default is "merge", which
\r
330 shows a <literal><<<<<<<</literal> conflict marker, changes made by one side,
\r
331 a <literal>=======</literal> marker, changes made by the other side, and then
\r
332 a <literal>>>>>>>></literal> marker. An alternate style, "diff3", adds a <literal>|||||||</literal>
\r
333 marker and the original text before the <literal>=======</literal> marker.
\r
343 Whether to include summaries of merged commits in newly created
\r
344 merge commit messages. False by default.
\r
354 The number of files to consider when performing rename detection
\r
355 during a merge; if not specified, defaults to the value of
\r
366 Whether to print the diffstat between ORIG_HEAD and the merge result
\r
367 at the end of the merge. True by default.
\r
377 Controls which merge resolution program is used by
\r
378 <xref linkend="git-mergetool(1)"/>. Valid built-in values are: "kdiff3",
\r
379 "tkdiff", "meld", "xxdiff", "emerge", "vimdiff", "gvimdiff", and
\r
380 "opendiff". Any other value is treated is custom merge tool
\r
381 and there must be a corresponding mergetool.<tool>.cmd option.
\r
391 Controls the amount of output shown by the recursive merge
\r
392 strategy. Level 0 outputs nothing except a final error
\r
393 message if conflicts were detected. Level 1 outputs only
\r
394 conflicts, 2 outputs conflicts and file changes. Level 5 and
\r
395 above outputs debugging information. The default is level 2.
\r
396 Can be overridden by the <emphasis>GIT_MERGE_VERBOSITY</emphasis> environment variable.
\r
402 merge.<driver>.name
\r
406 Defines a human-readable name for a custom low-level
\r
407 merge driver. See <xref linkend="gitattributes(5)"/> for details.
\r
413 merge.<driver>.driver
\r
417 Defines the command that implements a custom low-level
\r
418 merge driver. See <xref linkend="gitattributes(5)"/> for details.
\r
424 merge.<driver>.recursive
\r
428 Names a low-level merge driver to be used when
\r
429 performing an internal merge between common ancestors.
\r
430 See <xref linkend="gitattributes(5)"/> for details.
\r
436 branch.<name>.mergeoptions
\r
440 Sets default options for merging into branch <name>. The syntax and
\r
441 supported options are equal to that of <emphasis>git-merge</emphasis>, but option values
\r
442 containing whitespace characters are currently not supported.
\r
448 <simplesect id="_how_merge_works">
\r
449 <title>HOW MERGE WORKS</title>
\r
450 <simpara>A merge is always between the current <literal>HEAD</literal> and one or more
\r
451 commits (usually, branch head or tag), and the index file must
\r
452 match the tree of <literal>HEAD</literal> commit (i.e. the contents of the last commit)
\r
453 when it starts out. In other words, <literal>git diff --cached HEAD</literal> must
\r
454 report no changes. (One exception is when the changed index
\r
455 entries are already in the same state that would result from
\r
456 the merge anyway.)</simpara>
\r
457 <simpara>Three kinds of merge can happen:</simpara>
\r
461 The merged commit is already contained in <literal>HEAD</literal>. This is the
\r
462 simplest case, called "Already up-to-date."
\r
467 <literal>HEAD</literal> is already contained in the merged commit. This is the
\r
468 most common case especially when invoked from <emphasis>git pull</emphasis>:
\r
469 you are tracking an upstream repository, have committed no local
\r
470 changes and now you want to update to a newer upstream revision.
\r
471 Your <literal>HEAD</literal> (and the index) is updated to point at the merged
\r
472 commit, without creating an extra merge commit. This is
\r
473 called "Fast-forward".
\r
478 Both the merged commit and <literal>HEAD</literal> are independent and must be
\r
479 tied together by a merge commit that has both of them as its parents.
\r
480 The rest of this section describes this "True merge" case.
\r
484 <simpara>The chosen merge strategy merges the two commits into a single
\r
486 When things merge cleanly, this is what happens:</simpara>
\r
487 <orderedlist numeration="arabic">
\r
490 The results are updated both in the index file and in your
\r
496 Index file is written out as a tree;
\r
501 The tree gets committed; and
\r
506 The <literal>HEAD</literal> pointer gets advanced.
\r
510 <simpara>Because of 2., we require that the original state of the index
\r
511 file matches exactly the current <literal>HEAD</literal> commit; otherwise we
\r
512 will write out your local changes already registered in your
\r
513 index file along with the merge result, which is not good.
\r
514 Because 1. involves only those paths differing between your
\r
515 branch and the remote branch you are pulling from during the
\r
516 merge (which is typically a fraction of the whole tree), you can
\r
517 have local modifications in your working tree as long as they do
\r
518 not overlap with what the merge updates.</simpara>
\r
519 <simpara>When there are conflicts, the following happens:</simpara>
\r
520 <orderedlist numeration="arabic">
\r
523 <literal>HEAD</literal> stays the same.
\r
528 Cleanly merged paths are updated both in the index file and
\r
529 in your working tree.
\r
534 For conflicting paths, the index file records up to three
\r
535 versions; stage1 stores the version from the common ancestor,
\r
536 stage2 from <literal>HEAD</literal>, and stage3 from the remote branch (you
\r
537 can inspect the stages with <literal>git ls-files -u</literal>). The working
\r
538 tree files contain the result of the "merge" program; i.e. 3-way
\r
539 merge results with familiar conflict markers <literal><<< === >>></literal>.
\r
544 No other changes are done. In particular, the local
\r
545 modifications you had before you started merge will stay the
\r
546 same and the index entries for them stay as they were,
\r
547 i.e. matching <literal>HEAD</literal>.
\r
552 <simplesect id="_how_conflicts_are_presented">
\r
553 <title>HOW CONFLICTS ARE PRESENTED</title>
\r
554 <simpara>During a merge, the working tree files are updated to reflect the result
\r
555 of the merge. Among the changes made to the common ancestor’s version,
\r
556 non-overlapping ones (that is, you changed an area of the file while the
\r
557 other side left that area intact, or vice versa) are incorporated in the
\r
558 final result verbatim. When both sides made changes to the same area,
\r
559 however, git cannot randomly pick one side over the other, and asks you to
\r
560 resolve it by leaving what both sides did to that area.</simpara>
\r
561 <simpara>By default, git uses the same style as that is used by "merge" program
\r
562 from the RCS suite to present such a conflicted hunk, like this:</simpara>
\r
563 <literallayout>Here are lines that are either unchanged from the common
\r
564 ancestor, or cleanly resolved because only one side changed.
\r
565 <<<<<<< yours:sample.txt
\r
566 Conflict resolution is hard;
\r
569 Git makes conflict resolution easy.
\r
570 >>>>>>> theirs:sample.txt
\r
571 And here is another line that is cleanly resolved or unmodified.</literallayout>
\r
572 <simpara>The area where a pair of conflicting changes happened is marked with markers
\r
573 "<literal><<<<<<<</literal>", "<literal>=======</literal>", and "<literal>>>>>>>></literal>". The part before the "<literal>=======</literal>"
\r
574 is typically your side, and the part afterwards is typically their side.</simpara>
\r
575 <simpara>The default format does not show what the original said in the conflicting
\r
576 area. You cannot tell how many lines are deleted and replaced with
\r
577 Barbie’s remark on your side. The only thing you can tell is that your
\r
578 side wants to say it is hard and you’d prefer to go shopping, while the
\r
579 other side wants to claim it is easy.</simpara>
\r
580 <simpara>An alternative style can be used by setting the "merge.conflictstyle"
\r
581 configuration variable to "diff3". In "diff3" style, the above conflict
\r
582 may look like this:</simpara>
\r
583 <literallayout>Here are lines that are either unchanged from the common
\r
584 ancestor, or cleanly resolved because only one side changed.
\r
585 <<<<<<< yours:sample.txt
\r
586 Conflict resolution is hard;
\r
589 Conflict resolution is hard.
\r
591 Git makes conflict resolution easy.
\r
592 >>>>>>> theirs:sample.txt
\r
593 And here is another line that is cleanly resolved or unmodified.</literallayout>
\r
594 <simpara>In addition to the "<literal><<<<<<<</literal>", "<literal>=======</literal>", and "<literal>>>>>>>></literal>" markers, it uses
\r
595 another "<literal>|||||||</literal>" marker that is followed by the original text. You can
\r
596 tell that the original just stated a fact, and your side simply gave in to
\r
597 that statement and gave up, while the other side tried to have a more
\r
598 positive attitude. You can sometimes come up with a better resolution by
\r
599 viewing the original.</simpara>
\r
601 <simplesect id="_how_to_resolve_conflicts">
\r
602 <title>HOW TO RESOLVE CONFLICTS</title>
\r
603 <simpara>After seeing a conflict, you can do two things:</simpara>
\r
607 Decide not to merge. The only clean-ups you need are to reset
\r
608 the index file to the <literal>HEAD</literal> commit to reverse 2. and to clean
\r
609 up working tree changes made by 2. and 3.; <emphasis>git-reset --hard</emphasis> can
\r
615 Resolve the conflicts. Git will mark the conflicts in
\r
616 the working tree. Edit the files into shape and
\r
617 <emphasis>git-add</emphasis> them to the index. Use <emphasis>git-commit</emphasis> to seal the deal.
\r
621 <simpara>You can work through the conflict with a number of tools:</simpara>
\r
625 Use a mergetool. <emphasis>git mergetool</emphasis> to launch a graphical
\r
626 mergetool which will work you through the merge.
\r
631 Look at the diffs. <emphasis>git diff</emphasis> will show a three-way diff,
\r
632 highlighting changes from both the HEAD and remote versions.
\r
637 Look at the diffs on their own. <emphasis>git log --merge -p <path></emphasis>
\r
638 will show diffs first for the HEAD version and then the
\r
644 Look at the originals. <emphasis>git show :1:filename</emphasis> shows the
\r
645 common ancestor, <emphasis>git show :2:filename</emphasis> shows the HEAD
\r
646 version and <emphasis>git show :3:filename</emphasis> shows the remote version.
\r
651 <simplesect id="_see_also">
\r
652 <title>SEE ALSO</title>
\r
653 <simpara><xref linkend="git-fmt-merge-msg(1)"/>, <xref linkend="git-pull(1)"/>,
\r
654 <xref linkend="gitattributes(5)"/>,
\r
655 <xref linkend="git-reset(1)"/>,
\r
656 <xref linkend="git-diff(1)"/>, <xref linkend="git-ls-files(1)"/>,
\r
657 <xref linkend="git-add(1)"/>, <xref linkend="git-rm(1)"/>,
\r
658 <xref linkend="git-mergetool(1)"/></simpara>
\r
660 <simplesect id="_author">
\r
661 <title>Author</title>
\r
662 <simpara>Written by Junio C Hamano <<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>></simpara>
\r
664 <simplesect id="_documentation">
\r
665 <title>Documentation</title>
\r
666 <simpara>Documentation by Junio C Hamano and the git-list <<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>>.</simpara>
\r
668 <simplesect id="_git">
\r
670 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
\r