blob: 2912de706bf3921f817c9d18c66e526fd0a0fa8e [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231MERGE STRATEGIES
2----------------
3
Junio C Hamano3214e5f2014-03-25 19:54:384The merge mechanism (`git merge` and `git pull` commands) allows the
Junio C Hamano1aa40d22010-01-21 17:46:435backend 'merge strategies' to be chosen with `-s` option. Some strategies
6can also take their own options, which can be passed by giving `-X<option>`
Junio C Hamano3214e5f2014-03-25 19:54:387arguments to `git merge` and/or `git pull`.
Junio C Hamano1aa40d22010-01-21 17:46:438
Junio C Hamano1a4e8412005-12-27 08:17:239resolve::
10This can only resolve two heads (i.e. the current branch
Junio C Hamano1de75722009-03-26 08:39:3811and another branch you pulled from) using a 3-way merge
Junio C Hamano1a4e8412005-12-27 08:17:2312algorithm. It tries to carefully detect criss-cross
13merge ambiguities and is considered generally safe and
14fast.
15
16recursive::
Junio C Hamano1de75722009-03-26 08:39:3817This 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
Junio C Hamano1a4e8412005-12-27 08:17:2320merged 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
Junio C Hamano5b3533d2014-02-27 23:07:1523causing mismerges by tests done on actual merge commits
Junio C Hamano1a4e8412005-12-27 08:17:2324taken from Linux 2.6 kernel development history.
25Additionally this can detect and handle merges involving
Junio C Hamano309465b2018-05-30 06:32:5926renames, but currently cannot make use of detected
27copies. This is the default merge strategy when pulling
28or merging one branch.
Junio C Hamano1aa40d22010-01-21 17:46:4329+
30The 'recursive' strategy can take the following options:
31
32ours;;
33This option forces conflicting hunks to be auto-resolved cleanly by
34favoring 'our' version. Changes from the other tree that do not
Junio C Hamano8ef91f32019-12-01 22:58:2735conflict with our side are reflected in the merge result.
Junio C Hamanoa3cfb762012-09-15 05:32:1436For a binary file, the entire contents are taken from our side.
Junio C Hamano1aa40d22010-01-21 17:46:4337+
38This should not be confused with the 'ours' merge strategy, which does not
39even look at what the other tree contains at all. It discards everything
40the other tree did, declaring 'our' history contains all that happened in it.
41
42theirs;;
Junio C Hamanof0888582017-09-28 06:34:3943This is the opposite of 'ours'; note that, unlike 'ours', there is
Junio C Hamano81000162018-03-21 19:54:5044no 'theirs' merge strategy to confuse this merge option with.
Junio C Hamano1aa40d22010-01-21 17:46:4345
Junio C Hamano39c7a692010-10-27 06:08:5446patience;;
47With this option, 'merge-recursive' spends a little extra time
48to avoid mismerges that sometimes occur due to unimportant
49matching lines (e.g., braces from distinct functions). Use
50this when the branches to be merged have diverged wildly.
51See also linkgit:git-diff[1] `--patience`.
52
Junio C Hamano1575c202013-04-15 20:25:5953diff-algorithm=[patience|minimal|histogram|myers];;
54Tells 'merge-recursive' to use a different diff algorithm, which
55can help avoid mismerges that occur due to unimportant matching
56lines (such as braces from distinct functions). See also
57linkgit:git-diff[1] `--diff-algorithm`.
58
Junio C Hamano39c7a692010-10-27 06:08:5459ignore-space-change;;
60ignore-all-space;;
61ignore-space-at-eol;;
Junio C Hamano4886c772017-11-27 03:33:2862ignore-cr-at-eol;;
Junio C Hamano39c7a692010-10-27 06:08:5463Treats lines with the indicated type of whitespace change as
64unchanged for the sake of a three-way merge. Whitespace
65changes mixed with other changes to a line are not ignored.
Junio C Hamano4886c772017-11-27 03:33:2866See also linkgit:git-diff[1] `-b`, `-w`,
67`--ignore-space-at-eol`, and `--ignore-cr-at-eol`.
Junio C Hamano39c7a692010-10-27 06:08:5468+
69* If 'their' version only introduces whitespace changes to a line,
70 'our' version is used;
71* If 'our' version introduces whitespace changes but 'their'
72 version includes a substantial change, 'their' version is used;
73* Otherwise, the merge proceeds in the usual way.
74
Junio C Hamano2db3e752010-09-03 21:33:0675renormalize;;
76This runs a virtual check-out and check-in of all three stages
77of a file when resolving a three-way merge. This option is
78meant to be used when merging branches with different clean
79filters or end-of-line normalization rules. See "Merging
80branches with differing checkin/checkout attributes" in
81linkgit:gitattributes[5] for details.
82
83no-renormalize;;
84Disables the `renormalize` option. This overrides the
85`merge.renormalize` configuration variable.
86
Junio C Hamano76df4f72016-02-26 22:13:1087no-renames;;
Junio C Hamano309465b2018-05-30 06:32:5988Turn off rename detection. This overrides the `merge.renames`
89configuration variable.
Junio C Hamano76df4f72016-02-26 22:13:1090See also linkgit:git-diff[1] `--no-renames`.
91
92find-renames[=<n>];;
93Turn on rename detection, optionally setting the similarity
Junio C Hamano309465b2018-05-30 06:32:5994threshold. This is the default. This overrides the
95'merge.renames' configuration variable.
Junio C Hamano76df4f72016-02-26 22:13:1096See also linkgit:git-diff[1] `--find-renames`.
97
Junio C Hamano39c7a692010-10-27 06:08:5498rename-threshold=<n>;;
Junio C Hamano76df4f72016-02-26 22:13:1099Deprecated synonym for `find-renames=<n>`.
Junio C Hamano39c7a692010-10-27 06:08:54100
Junio C Hamanod2179ef2010-10-22 04:12:17101subtree[=<path>];;
Junio C Hamano1aa40d22010-01-21 17:46:43102This option is a more advanced form of 'subtree' strategy, where
103the strategy makes a guess on how two trees must be shifted to
104match with each other when merging. Instead, the specified path
105is prefixed (or stripped from the beginning) to make the shape of
106two trees to match.
Junio C Hamano1a4e8412005-12-27 08:17:23107
108octopus::
Junio C Hamano1de75722009-03-26 08:39:38109This resolves cases with more than two heads, but refuses to do
110a complex merge that needs manual resolution. It is
Junio C Hamano1a4e8412005-12-27 08:17:23111primarily meant to be used for bundling topic branch
112heads together. This is the default merge strategy when
Junio C Hamano1de75722009-03-26 08:39:38113pulling or merging more than one branch.
Junio C Hamano1a4e8412005-12-27 08:17:23114
115ours::
Junio C Hamanobf984de2009-11-23 06:11:19116This resolves any number of heads, but the resulting tree of the
117merge is always that of the current branch head, effectively
118ignoring all changes from all other branches. It is meant to
Junio C Hamano1a4e8412005-12-27 08:17:23119be used to supersede old development history of side
Junio C Hamano1aa40d22010-01-21 17:46:43120branches. Note that this is different from the -Xours option to
121the 'recursive' merge strategy.
Junio C Hamanoe6c92032008-03-19 09:24:34122
123subtree::
124This is a modified recursive strategy. When merging trees A and
125B, if B corresponds to a subtree of A, B is first adjusted to
126match the tree structure of A, instead of reading the trees at
127the same level. This adjustment is also done to the common
128ancestor tree.
Junio C Hamanocf77b042013-12-17 23:54:21129
130With the strategies that use 3-way merge (including the default, 'recursive'),
131if a change is made on both branches, but later reverted on one of the
132branches, that change will be present in the merged result; some people find
133this behavior confusing. It occurs because only the heads and the merge base
134are considered when performing a merge, not the individual commits. The merge
135algorithm therefore considers the reverted change as no change at all, and
136substitutes the changed version instead.