blob: 5fc54ec060b9638e11c66231eed6304de1772313 [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 Hamano7a031e52021-08-30 23:54:259ort::
10This is the default merge strategy when pulling or merging one
11branch. This strategy can only resolve two heads using a
123-way merge algorithm. When there is more than one common
13ancestor that can be used for 3-way merge, it creates a merged
14tree of the common ancestors and uses that as the reference
15tree for the 3-way merge. This has been reported to result in
16fewer merge conflicts without causing mismerges by tests done
17on actual merge commits taken from Linux 2.6 kernel
18development history. Additionally this strategy can detect
19and handle merges involving renames. It does not make use of
20detected copies. The name for this algorithm is an acronym
21("Ostensibly Recursive's Twin") and came from the fact that it
22was written as a replacement for the previous default
23algorithm, `recursive`.
Junio C Hamano1aa40d22010-01-21 17:46:4324+
Junio C Hamano7a031e52021-08-30 23:54:2525The 'ort' strategy can take the following options:
Junio C Hamano1aa40d22010-01-21 17:46:4326
27ours;;
28This option forces conflicting hunks to be auto-resolved cleanly by
29favoring 'our' version. Changes from the other tree that do not
Junio C Hamano8ef91f32019-12-01 22:58:2730conflict with our side are reflected in the merge result.
Junio C Hamanoa3cfb762012-09-15 05:32:1431For a binary file, the entire contents are taken from our side.
Junio C Hamano1aa40d22010-01-21 17:46:4332+
33This should not be confused with the 'ours' merge strategy, which does not
34even look at what the other tree contains at all. It discards everything
35the other tree did, declaring 'our' history contains all that happened in it.
36
37theirs;;
Junio C Hamanof0888582017-09-28 06:34:3938This is the opposite of 'ours'; note that, unlike 'ours', there is
Junio C Hamano81000162018-03-21 19:54:5039no 'theirs' merge strategy to confuse this merge option with.
Junio C Hamano1aa40d22010-01-21 17:46:4340
Junio C Hamano39c7a692010-10-27 06:08:5441ignore-space-change;;
42ignore-all-space;;
43ignore-space-at-eol;;
Junio C Hamano4886c772017-11-27 03:33:2844ignore-cr-at-eol;;
Junio C Hamano39c7a692010-10-27 06:08:5445Treats lines with the indicated type of whitespace change as
46unchanged for the sake of a three-way merge. Whitespace
47changes mixed with other changes to a line are not ignored.
Junio C Hamano4886c772017-11-27 03:33:2848See also linkgit:git-diff[1] `-b`, `-w`,
49`--ignore-space-at-eol`, and `--ignore-cr-at-eol`.
Junio C Hamano39c7a692010-10-27 06:08:5450+
51* If 'their' version only introduces whitespace changes to a line,
52 'our' version is used;
53* If 'our' version introduces whitespace changes but 'their'
54 version includes a substantial change, 'their' version is used;
55* Otherwise, the merge proceeds in the usual way.
56
Junio C Hamano2db3e752010-09-03 21:33:0657renormalize;;
58This runs a virtual check-out and check-in of all three stages
59of a file when resolving a three-way merge. This option is
60meant to be used when merging branches with different clean
61filters or end-of-line normalization rules. See "Merging
62branches with differing checkin/checkout attributes" in
63linkgit:gitattributes[5] for details.
64
65no-renormalize;;
66Disables the `renormalize` option. This overrides the
67`merge.renormalize` configuration variable.
68
Junio C Hamano76df4f72016-02-26 22:13:1069find-renames[=<n>];;
70Turn on rename detection, optionally setting the similarity
Junio C Hamano309465b2018-05-30 06:32:5971threshold. This is the default. This overrides the
72'merge.renames' configuration variable.
Junio C Hamano76df4f72016-02-26 22:13:1073See also linkgit:git-diff[1] `--find-renames`.
74
Junio C Hamano39c7a692010-10-27 06:08:5475rename-threshold=<n>;;
Junio C Hamano76df4f72016-02-26 22:13:1076Deprecated synonym for `find-renames=<n>`.
Junio C Hamano39c7a692010-10-27 06:08:5477
Junio C Hamanod2179ef2010-10-22 04:12:1778subtree[=<path>];;
Junio C Hamano1aa40d22010-01-21 17:46:4379This option is a more advanced form of 'subtree' strategy, where
80the strategy makes a guess on how two trees must be shifted to
81match with each other when merging. Instead, the specified path
82is prefixed (or stripped from the beginning) to make the shape of
83two trees to match.
Junio C Hamano1a4e8412005-12-27 08:17:2384
Junio C Hamano7a031e52021-08-30 23:54:2585recursive::
86This can only resolve two heads using a 3-way merge
87algorithm. When there is more than one common
88ancestor that can be used for 3-way merge, it creates a
89merged tree of the common ancestors and uses that as
90the reference tree for the 3-way merge. This has been
91reported to result in fewer merge conflicts without
92causing mismerges by tests done on actual merge commits
93taken from Linux 2.6 kernel development history.
94Additionally this can detect and handle merges involving
95renames. It does not make use of detected copies. This was
96the default strategy for resolving two heads from Git v0.99.9k
97until v2.33.0.
98+
99The 'recursive' strategy takes the same options as 'ort'. However,
100there are three additional options that 'ort' ignores (not documented
101above) that are potentially useful with the 'recursive' strategy:
102
103patience;;
104Deprecated synonym for `diff-algorithm=patience`.
105
106diff-algorithm=[patience|minimal|histogram|myers];;
107Use a different diff algorithm while merging, which can help
108avoid mismerges that occur due to unimportant matching lines
109(such as braces from distinct functions). See also
110linkgit:git-diff[1] `--diff-algorithm`. Note that `ort`
111specifically uses `diff-algorithm=histogram`, while `recursive`
112defaults to the `diff.algorithm` config setting.
113
114no-renames;;
115Turn off rename detection. This overrides the `merge.renames`
116configuration variable.
117See also linkgit:git-diff[1] `--no-renames`.
118
119resolve::
120This can only resolve two heads (i.e. the current branch
121and another branch you pulled from) using a 3-way merge
122algorithm. It tries to carefully detect criss-cross
123merge ambiguities. It does not handle renames.
124
Junio C Hamano1a4e8412005-12-27 08:17:23125octopus::
Junio C Hamano1de75722009-03-26 08:39:38126This resolves cases with more than two heads, but refuses to do
127a complex merge that needs manual resolution. It is
Junio C Hamano1a4e8412005-12-27 08:17:23128primarily meant to be used for bundling topic branch
129heads together. This is the default merge strategy when
Junio C Hamano1de75722009-03-26 08:39:38130pulling or merging more than one branch.
Junio C Hamano1a4e8412005-12-27 08:17:23131
132ours::
Junio C Hamanobf984de2009-11-23 06:11:19133This resolves any number of heads, but the resulting tree of the
134merge is always that of the current branch head, effectively
135ignoring all changes from all other branches. It is meant to
Junio C Hamano1a4e8412005-12-27 08:17:23136be used to supersede old development history of side
Junio C Hamano1aa40d22010-01-21 17:46:43137branches. Note that this is different from the -Xours option to
138the 'recursive' merge strategy.
Junio C Hamanoe6c92032008-03-19 09:24:34139
140subtree::
Junio C Hamano7a031e52021-08-30 23:54:25141This is a modified `ort` strategy. When merging trees A and
Junio C Hamanoe6c92032008-03-19 09:24:34142B, if B corresponds to a subtree of A, B is first adjusted to
143match the tree structure of A, instead of reading the trees at
144the same level. This adjustment is also done to the common
145ancestor tree.
Junio C Hamanocf77b042013-12-17 23:54:21146
Junio C Hamano7a031e52021-08-30 23:54:25147With the strategies that use 3-way merge (including the default, 'ort'),
Junio C Hamanocf77b042013-12-17 23:54:21148if a change is made on both branches, but later reverted on one of the
149branches, that change will be present in the merged result; some people find
150this behavior confusing. It occurs because only the heads and the merge base
151are considered when performing a merge, not the individual commits. The merge
152algorithm therefore considers the reverted change as no change at all, and
153substitutes the changed version instead.