1MERGE STRATEGIES
2----------------
34
The 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`.
89
resolve::
10This can only resolve two heads (i.e. the current branch
11and another branch you pulled from) using a 3-way merge
12algorithm. It tries to carefully detect criss-cross
13merge ambiguities and is considered generally safe and
14fast.
1516
recursive::
17This can only resolve two heads using a 3-way merge
18algorithm. When there is more than one common
19ancestor that can be used for 3-way merge, it creates a
20merged tree of the common ancestors and uses that as
21the reference tree for the 3-way merge. This has been
22reported to result in fewer merge conflicts without
23causing mismerges by tests done on actual merge commits
24taken from Linux 2.6 kernel development history.
25Additionally this can detect and handle merges involving
26renames. This is the default merge strategy when
27pulling or merging one branch.
28+
29The 'recursive' strategy can take the following options:
3031
ours;;
32This option forces conflicting hunks to be auto-resolved cleanly by
33favoring 'our' version. Changes from the other tree that do not
34conflict with our side are reflected to the merge result.
35For 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.
4041
theirs;;
42This is the opposite of 'ours'; note that, unlike 'ours', there is
43no 'theirs' merge stragegy to confuse this merge option with.
4445
patience;;
46With this option, 'merge-recursive' spends a little extra time
47to avoid mismerges that sometimes occur due to unimportant
48matching lines (e.g., braces from distinct functions). Use
49this when the branches to be merged have diverged wildly.
50See also linkgit:git-diff[1] `--patience`.
5152
diff-algorithm=[patience|minimal|histogram|myers];;
53Tells 'merge-recursive' to use a different diff algorithm, which
54can help avoid mismerges that occur due to unimportant matching
55lines (such as braces from distinct functions). See also
56linkgit:git-diff[1] `--diff-algorithm`.
5758
ignore-space-change;;
59ignore-all-space;;
60ignore-space-at-eol;;
61Treats lines with the indicated type of whitespace change as
62unchanged for the sake of a three-way merge. Whitespace
63changes mixed with other changes to a line are not ignored.
64See also linkgit:git-diff[1] `-b`, `-w`, and
65`--ignore-space-at-eol`.
66+
67* If 'their' version only introduces whitespace changes to a line,
68'our' version is used;
69* If 'our' version introduces whitespace changes but 'their'
70version includes a substantial change, 'their' version is used;
71* Otherwise, the merge proceeds in the usual way.
7273
renormalize;;
74This runs a virtual check-out and check-in of all three stages
75of a file when resolving a three-way merge. This option is
76meant to be used when merging branches with different clean
77filters or end-of-line normalization rules. See "Merging
78branches with differing checkin/checkout attributes" in
79linkgit:gitattributes[5] for details.
8081
no-renormalize;;
82Disables the `renormalize` option. This overrides the
83`merge.renormalize` configuration variable.
8485
no-renames;;
86Turn off rename detection.
87See also linkgit:git-diff[1] `--no-renames`.
8889
find-renames[=<n>];;
90Turn on rename detection, optionally setting the similarity
91threshold. This is the default.
92See also linkgit:git-diff[1] `--find-renames`.
9394
rename-threshold=<n>;;
95Deprecated synonym for `find-renames=<n>`.
9697
subtree[=<path>];;
98This option is a more advanced form of 'subtree' strategy, where
99the strategy makes a guess on how two trees must be shifted to
100match with each other when merging. Instead, the specified path
101is prefixed (or stripped from the beginning) to make the shape of
102two trees to match.
103104
octopus::
105This resolves cases with more than two heads, but refuses to do
106a complex merge that needs manual resolution. It is
107primarily meant to be used for bundling topic branch
108heads together. This is the default merge strategy when
109pulling or merging more than one branch.
110111
ours::
112This resolves any number of heads, but the resulting tree of the
113merge is always that of the current branch head, effectively
114ignoring all changes from all other branches. It is meant to
115be used to supersede old development history of side
116branches. Note that this is different from the -Xours option to
117the 'recursive' merge strategy.
118119
subtree::
120This is a modified recursive strategy. When merging trees A and
121B, if B corresponds to a subtree of A, B is first adjusted to
122match the tree structure of A, instead of reading the trees at
123the same level. This adjustment is also done to the common
124ancestor tree.
125126
With the strategies that use 3-way merge (including the default, 'recursive'),
127if a change is made on both branches, but later reverted on one of the
128branches, that change will be present in the merged result; some people find
129this behavior confusing. It occurs because only the heads and the merge base
130are considered when performing a merge, not the individual commits. The merge
131algorithm therefore considers the reverted change as no change at all, and
132substitutes the changed version instead.