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'.
4344
patience;;
45With this option, 'merge-recursive' spends a little extra time
46to avoid mismerges that sometimes occur due to unimportant
47matching lines (e.g., braces from distinct functions). Use
48this when the branches to be merged have diverged wildly.
49See also linkgit:git-diff[1] `--patience`.
5051
diff-algorithm=[patience|minimal|histogram|myers];;
52Tells 'merge-recursive' to use a different diff algorithm, which
53can help avoid mismerges that occur due to unimportant matching
54lines (such as braces from distinct functions). See also
55linkgit:git-diff[1] `--diff-algorithm`.
5657
ignore-space-change;;
58ignore-all-space;;
59ignore-space-at-eol;;
60Treats lines with the indicated type of whitespace change as
61unchanged for the sake of a three-way merge. Whitespace
62changes mixed with other changes to a line are not ignored.
63See 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'
69version includes a substantial change, 'their' version is used;
70* Otherwise, the merge proceeds in the usual way.
7172
renormalize;;
73This runs a virtual check-out and check-in of all three stages
74of a file when resolving a three-way merge. This option is
75meant to be used when merging branches with different clean
76filters or end-of-line normalization rules. See "Merging
77branches with differing checkin/checkout attributes" in
78linkgit:gitattributes[5] for details.
7980
no-renormalize;;
81Disables the `renormalize` option. This overrides the
82`merge.renormalize` configuration variable.
8384
no-renames;;
85Turn off rename detection.
86See also linkgit:git-diff[1] `--no-renames`.
8788
find-renames[=<n>];;
89Turn on rename detection, optionally setting the similarity
90threshold. This is the default.
91See also linkgit:git-diff[1] `--find-renames`.
9293
rename-threshold=<n>;;
94Deprecated synonym for `find-renames=<n>`.
9596
subtree[=<path>];;
97This option is a more advanced form of 'subtree' strategy, where
98the strategy makes a guess on how two trees must be shifted to
99match with each other when merging. Instead, the specified path
100is prefixed (or stripped from the beginning) to make the shape of
101two trees to match.
102103
octopus::
104This resolves cases with more than two heads, but refuses to do
105a complex merge that needs manual resolution. It is
106primarily meant to be used for bundling topic branch
107heads together. This is the default merge strategy when
108pulling or merging more than one branch.
109110
ours::
111This resolves any number of heads, but the resulting tree of the
112merge is always that of the current branch head, effectively
113ignoring all changes from all other branches. It is meant to
114be used to supersede old development history of side
115branches. Note that this is different from the -Xours option to
116the 'recursive' merge strategy.
117118
subtree::
119This is a modified recursive strategy. When merging trees A and
120B, if B corresponds to a subtree of A, B is first adjusted to
121match the tree structure of A, instead of reading the trees at
122the same level. This adjustment is also done to the common
123ancestor tree.
124125
With the strategies that use 3-way merge (including the default, 'recursive'),
126if a change is made on both branches, but later reverted on one of the
127branches, that change will be present in the merged result; some people find
128this behavior confusing. It occurs because only the heads and the merge base
129are considered when performing a merge, not the individual commits. The merge
130algorithm therefore considers the reverted change as no change at all, and
131substitutes the changed version instead.