1a5e1974a559a685f3231ff29c926c799ebcc1bf
   1MERGE STRATEGIES
   2----------------
   3
   4The merge mechanism (`git merge` and `git pull` commands) allows the
   5backend 'merge strategies' to be chosen with `-s` option.  Some strategies
   6can also take their own options, which can be passed by giving `-X<option>`
   7arguments to `git merge` and/or `git pull`.
   8
   9resolve::
  10        This can only resolve two heads (i.e. the current branch
  11        and another branch you pulled from) using a 3-way merge
  12        algorithm.  It tries to carefully detect criss-cross
  13        merge ambiguities and is considered generally safe and
  14        fast.
  15
  16recursive::
  17        This can only resolve two heads using a 3-way merge
  18        algorithm.  When there is more than one common
  19        ancestor that can be used for 3-way merge, it creates a
  20        merged tree of the common ancestors and uses that as
  21        the reference tree for the 3-way merge.  This has been
  22        reported to result in fewer merge conflicts without
  23        causing mismerges by tests done on actual merge commits
  24        taken from Linux 2.6 kernel development history.
  25        Additionally this can detect and handle merges involving
  26        renames.  This is the default merge strategy when
  27        pulling or merging one branch.
  28+
  29The 'recursive' strategy can take the following options:
  30
  31ours;;
  32        This option forces conflicting hunks to be auto-resolved cleanly by
  33        favoring 'our' version.  Changes from the other tree that do not
  34        conflict with our side are reflected to the merge result.
  35        For a binary file, the entire contents are taken from our side.
  36+
  37This should not be confused with the 'ours' merge strategy, which does not
  38even look at what the other tree contains at all.  It discards everything
  39the other tree did, declaring 'our' history contains all that happened in it.
  40
  41theirs;;
  42        This is the opposite of 'ours'.
  43
  44patience;;
  45        With this option, 'merge-recursive' spends a little extra time
  46        to avoid mismerges that sometimes occur due to unimportant
  47        matching lines (e.g., braces from distinct functions).  Use
  48        this when the branches to be merged have diverged wildly.
  49        See also linkgit:git-diff[1] `--patience`.
  50
  51diff-algorithm=[patience|minimal|histogram|myers];;
  52        Tells 'merge-recursive' to use a different diff algorithm, which
  53        can help avoid mismerges that occur due to unimportant matching
  54        lines (such as braces from distinct functions).  See also
  55        linkgit:git-diff[1] `--diff-algorithm`.
  56
  57ignore-space-change;;
  58ignore-all-space;;
  59ignore-space-at-eol;;
  60        Treats lines with the indicated type of whitespace change as
  61        unchanged for the sake of a three-way merge.  Whitespace
  62        changes mixed with other changes to a line are not ignored.
  63        See also linkgit:git-diff[1] `-b`, `-w`, and
  64        `--ignore-space-at-eol`.
  65+
  66* If 'their' version only introduces whitespace changes to a line,
  67  'our' version is used;
  68* If 'our' version introduces whitespace changes but 'their'
  69  version includes a substantial change, 'their' version is used;
  70* Otherwise, the merge proceeds in the usual way.
  71
  72renormalize;;
  73        This runs a virtual check-out and check-in of all three stages
  74        of a file when resolving a three-way merge.  This option is
  75        meant to be used when merging branches with different clean
  76        filters or end-of-line normalization rules.  See "Merging
  77        branches with differing checkin/checkout attributes" in
  78        linkgit:gitattributes[5] for details.
  79
  80no-renormalize;;
  81        Disables the `renormalize` option.  This overrides the
  82        `merge.renormalize` configuration variable.
  83
  84no-renames;;
  85        Turn off rename detection.
  86        See also linkgit:git-diff[1] `--no-renames`.
  87
  88rename-threshold=<n>;;
  89        Controls the similarity threshold used for rename detection.
  90        Re-enables rename detection if disabled by a preceding
  91        `no-renames`.
  92        See also linkgit:git-diff[1] `-M`.
  93
  94subtree[=<path>];;
  95        This option is a more advanced form of 'subtree' strategy, where
  96        the strategy makes a guess on how two trees must be shifted to
  97        match with each other when merging.  Instead, the specified path
  98        is prefixed (or stripped from the beginning) to make the shape of
  99        two trees to match.
 100
 101octopus::
 102        This resolves cases with more than two heads, but refuses to do
 103        a complex merge that needs manual resolution.  It is
 104        primarily meant to be used for bundling topic branch
 105        heads together.  This is the default merge strategy when
 106        pulling or merging more than one branch.
 107
 108ours::
 109        This resolves any number of heads, but the resulting tree of the
 110        merge is always that of the current branch head, effectively
 111        ignoring all changes from all other branches.  It is meant to
 112        be used to supersede old development history of side
 113        branches.  Note that this is different from the -Xours option to
 114        the 'recursive' merge strategy.
 115
 116subtree::
 117        This is a modified recursive strategy. When merging trees A and
 118        B, if B corresponds to a subtree of A, B is first adjusted to
 119        match the tree structure of A, instead of reading the trees at
 120        the same level. This adjustment is also done to the common
 121        ancestor tree.
 122
 123With the strategies that use 3-way merge (including the default, 'recursive'),
 124if a change is made on both branches, but later reverted on one of the
 125branches, that change will be present in the merged result; some people find
 126this behavior confusing.  It occurs because only the heads and the merge base
 127are considered when performing a merge, not the individual commits.  The merge
 128algorithm therefore considers the reverted change as no change at all, and
 129substitutes the changed version instead.