Documentation / git-merge.txton commit Support a --quiet option in the test-suite. (1ece127)
   1git-merge(1)
   2============
   3
   4NAME
   5----
   6git-merge - Join two or more development histories together
   7
   8
   9SYNOPSIS
  10--------
  11[verse]
  12'git-merge' [-n] [--summary] [--no-commit] [--squash] [-s <strategy>]...
  13        [-m <msg>] <remote> <remote>...
  14
  15DESCRIPTION
  16-----------
  17This is the top-level interface to the merge machinery
  18which drives multiple merge strategy scripts.
  19
  20
  21OPTIONS
  22-------
  23include::merge-options.txt[]
  24
  25<msg>::
  26        The commit message to be used for the merge commit (in case
  27        it is created). The `git-fmt-merge-msg` script can be used
  28        to give a good default for automated `git-merge` invocations.
  29
  30<head>::
  31        Our branch head commit.  This has to be `HEAD`, so new
  32        syntax does not require it
  33
  34<remote>::
  35        Other branch head merged into our branch.  You need at
  36        least one <remote>.  Specifying more than one <remote>
  37        obviously means you are trying an Octopus.
  38
  39include::merge-strategies.txt[]
  40
  41
  42If you tried a merge which resulted in a complex conflicts and
  43would want to start over, you can recover with
  44gitlink:git-reset[1].
  45
  46CONFIGURATION
  47-------------
  48
  49merge.summary::
  50        Whether to include summaries of merged commits in newly
  51        created merge commit. False by default.
  52
  53merge.verbosity::
  54        Controls the amount of output shown by the recursive merge
  55        strategy.  Level 0 outputs nothing except a final error
  56        message if conflicts were detected. Level 1 outputs only
  57        conflicts, 2 outputs conflicts and file changes.  Level 5 and
  58        above outputs debugging information.  The default is level 2.
  59        Can be overridden by 'GIT_MERGE_VERBOSITY' environment variable.
  60
  61branch.<name>.mergeoptions::
  62        Sets default options for merging into branch <name>. The syntax and
  63        supported options are equal to that of git-merge, but option values
  64        containing whitespace characters are currently not supported.
  65
  66HOW MERGE WORKS
  67---------------
  68
  69A merge is always between the current `HEAD` and one or more
  70remote branch heads, and the index file must exactly match the
  71tree of `HEAD` commit (i.e. the contents of the last commit) when
  72it happens.  In other words, `git-diff --cached HEAD` must
  73report no changes.
  74
  75[NOTE]
  76This is a bit of lie.  In certain special cases, your index are
  77allowed to be different from the tree of `HEAD` commit.  The most
  78notable case is when your `HEAD` commit is already ahead of what
  79is being merged, in which case your index can have arbitrary
  80difference from your `HEAD` commit.  Otherwise, your index entries
  81are allowed have differences from your `HEAD` commit that match
  82the result of trivial merge (e.g. you received the same patch
  83from external source to produce the same result as what you are
  84merging).  For example, if a path did not exist in the common
  85ancestor and your head commit but exists in the tree you are
  86merging into your repository, and if you already happen to have
  87that path exactly in your index, the merge does not have to
  88fail.
  89
  90Otherwise, merge will refuse to do any harm to your repository
  91(that is, it may fetch the objects from remote, and it may even
  92update the local branch used to keep track of the remote branch
  93with `git pull remote rbranch:lbranch`, but your working tree,
  94`.git/HEAD` pointer and index file are left intact).
  95
  96You may have local modifications in the working tree files.  In
  97other words, `git-diff` is allowed to report changes.
  98However, the merge uses your working tree as the working area,
  99and in order to prevent the merge operation from losing such
 100changes, it makes sure that they do not interfere with the
 101merge. Those complex tables in read-tree documentation define
 102what it means for a path to "interfere with the merge".  And if
 103your local modifications interfere with the merge, again, it
 104stops before touching anything.
 105
 106So in the above two "failed merge" case, you do not have to
 107worry about loss of data --- you simply were not ready to do
 108a merge, so no merge happened at all.  You may want to finish
 109whatever you were in the middle of doing, and retry the same
 110pull after you are done and ready.
 111
 112When things cleanly merge, these things happen:
 113
 1141. The results are updated both in the index file and in your
 115   working tree;
 1162. Index file is written out as a tree;
 1173. The tree gets committed; and
 1184. The `HEAD` pointer gets advanced.
 119
 120Because of 2., we require that the original state of the index
 121file to match exactly the current `HEAD` commit; otherwise we
 122will write out your local changes already registered in your
 123index file along with the merge result, which is not good.
 124Because 1. involves only the paths different between your
 125branch and the remote branch you are pulling from during the
 126merge (which is typically a fraction of the whole tree), you can
 127have local modifications in your working tree as long as they do
 128not overlap with what the merge updates.
 129
 130When there are conflicts, these things happen:
 131
 1321. `HEAD` stays the same.
 133
 1342. Cleanly merged paths are updated both in the index file and
 135   in your working tree.
 136
 1373. For conflicting paths, the index file records up to three
 138   versions; stage1 stores the version from the common ancestor,
 139   stage2 from `HEAD`, and stage3 from the remote branch (you
 140   can inspect the stages with `git-ls-files -u`).  The working
 141   tree files have the result of "merge" program; i.e. 3-way
 142   merge result with familiar conflict markers `<<< === >>>`.
 143
 1444. No other changes are done.  In particular, the local
 145   modifications you had before you started merge will stay the
 146   same and the index entries for them stay as they were,
 147   i.e. matching `HEAD`.
 148
 149After seeing a conflict, you can do two things:
 150
 151 * Decide not to merge.  The only clean-up you need are to reset
 152   the index file to the `HEAD` commit to reverse 2. and to clean
 153   up working tree changes made by 2. and 3.; `git-reset` can
 154   be used for this.
 155
 156 * Resolve the conflicts.  `git-diff` would report only the
 157   conflicting paths because of the above 2. and 3..  Edit the
 158   working tree files into a desirable shape, `git-add` or `git-rm`
 159   them, to make the index file contain what the merge result
 160   should be, and run `git-commit` to commit the result.
 161
 162
 163SEE ALSO
 164--------
 165gitlink:git-fmt-merge-msg[1], gitlink:git-pull[1]
 166
 167
 168Author
 169------
 170Written by Junio C Hamano <junkio@cox.net>
 171
 172
 173Documentation
 174--------------
 175Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 176
 177GIT
 178---
 179Part of the gitlink:git[7] suite