debian: new upstream release
[git/debian.git] / Documentation / merge-strategies.txt
blob5fc54ec060b9638e11c66231eed6304de1772313
1 MERGE STRATEGIES
2 ----------------
4 The merge mechanism (`git merge` and `git pull` commands) allows the
5 backend 'merge strategies' to be chosen with `-s` option.  Some strategies
6 can also take their own options, which can be passed by giving `-X<option>`
7 arguments to `git merge` and/or `git pull`.
9 ort::
10         This is the default merge strategy when pulling or merging one
11         branch.  This strategy can only resolve two heads using a
12         3-way merge algorithm.  When there is more than one common
13         ancestor that can be used for 3-way merge, it creates a merged
14         tree of the common ancestors and uses that as the reference
15         tree for the 3-way merge.  This has been reported to result in
16         fewer merge conflicts without causing mismerges by tests done
17         on actual merge commits taken from Linux 2.6 kernel
18         development history.  Additionally this strategy can detect
19         and handle merges involving renames.  It does not make use of
20         detected copies.  The name for this algorithm is an acronym
21         ("Ostensibly Recursive's Twin") and came from the fact that it
22         was written as a replacement for the previous default
23         algorithm, `recursive`.
25 The 'ort' strategy can take the following options:
27 ours;;
28         This option forces conflicting hunks to be auto-resolved cleanly by
29         favoring 'our' version.  Changes from the other tree that do not
30         conflict with our side are reflected in the merge result.
31         For a binary file, the entire contents are taken from our side.
33 This should not be confused with the 'ours' merge strategy, which does not
34 even look at what the other tree contains at all.  It discards everything
35 the other tree did, declaring 'our' history contains all that happened in it.
37 theirs;;
38         This is the opposite of 'ours'; note that, unlike 'ours', there is
39         no 'theirs' merge strategy to confuse this merge option with.
41 ignore-space-change;;
42 ignore-all-space;;
43 ignore-space-at-eol;;
44 ignore-cr-at-eol;;
45         Treats lines with the indicated type of whitespace change as
46         unchanged for the sake of a three-way merge.  Whitespace
47         changes mixed with other changes to a line are not ignored.
48         See also linkgit:git-diff[1] `-b`, `-w`,
49         `--ignore-space-at-eol`, and `--ignore-cr-at-eol`.
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.
57 renormalize;;
58         This runs a virtual check-out and check-in of all three stages
59         of a file when resolving a three-way merge.  This option is
60         meant to be used when merging branches with different clean
61         filters or end-of-line normalization rules.  See "Merging
62         branches with differing checkin/checkout attributes" in
63         linkgit:gitattributes[5] for details.
65 no-renormalize;;
66         Disables the `renormalize` option.  This overrides the
67         `merge.renormalize` configuration variable.
69 find-renames[=<n>];;
70         Turn on rename detection, optionally setting the similarity
71         threshold.  This is the default. This overrides the
72         'merge.renames' configuration variable.
73         See also linkgit:git-diff[1] `--find-renames`.
75 rename-threshold=<n>;;
76         Deprecated synonym for `find-renames=<n>`.
78 subtree[=<path>];;
79         This option is a more advanced form of 'subtree' strategy, where
80         the strategy makes a guess on how two trees must be shifted to
81         match with each other when merging.  Instead, the specified path
82         is prefixed (or stripped from the beginning) to make the shape of
83         two trees to match.
85 recursive::
86         This can only resolve two heads using a 3-way merge
87         algorithm.  When there is more than one common
88         ancestor that can be used for 3-way merge, it creates a
89         merged tree of the common ancestors and uses that as
90         the reference tree for the 3-way merge.  This has been
91         reported to result in fewer merge conflicts without
92         causing mismerges by tests done on actual merge commits
93         taken from Linux 2.6 kernel development history.
94         Additionally this can detect and handle merges involving
95         renames.  It does not make use of detected copies.  This was
96         the default strategy for resolving two heads from Git v0.99.9k
97         until v2.33.0.
99 The 'recursive' strategy takes the same options as 'ort'.  However,
100 there are three additional options that 'ort' ignores (not documented
101 above) that are potentially useful with the 'recursive' strategy:
103 patience;;
104         Deprecated synonym for `diff-algorithm=patience`.
106 diff-algorithm=[patience|minimal|histogram|myers];;
107         Use a different diff algorithm while merging, which can help
108         avoid mismerges that occur due to unimportant matching lines
109         (such as braces from distinct functions).  See also
110         linkgit:git-diff[1] `--diff-algorithm`.  Note that `ort`
111         specifically uses `diff-algorithm=histogram`, while `recursive`
112         defaults to the `diff.algorithm` config setting.
114 no-renames;;
115         Turn off rename detection. This overrides the `merge.renames`
116         configuration variable.
117         See also linkgit:git-diff[1] `--no-renames`.
119 resolve::
120         This can only resolve two heads (i.e. the current branch
121         and another branch you pulled from) using a 3-way merge
122         algorithm.  It tries to carefully detect criss-cross
123         merge ambiguities.  It does not handle renames.
125 octopus::
126         This resolves cases with more than two heads, but refuses to do
127         a complex merge that needs manual resolution.  It is
128         primarily meant to be used for bundling topic branch
129         heads together.  This is the default merge strategy when
130         pulling or merging more than one branch.
132 ours::
133         This resolves any number of heads, but the resulting tree of the
134         merge is always that of the current branch head, effectively
135         ignoring all changes from all other branches.  It is meant to
136         be used to supersede old development history of side
137         branches.  Note that this is different from the -Xours option to
138         the 'recursive' merge strategy.
140 subtree::
141         This is a modified `ort` strategy. When merging trees A and
142         B, if B corresponds to a subtree of A, B is first adjusted to
143         match the tree structure of A, instead of reading the trees at
144         the same level. This adjustment is also done to the common
145         ancestor tree.
147 With the strategies that use 3-way merge (including the default, 'ort'),
148 if a change is made on both branches, but later reverted on one of the
149 branches, that change will be present in the merged result; some people find
150 this behavior confusing.  It occurs because only the heads and the merge base
151 are considered when performing a merge, not the individual commits.  The merge
152 algorithm therefore considers the reverted change as no change at all, and
153 substitutes the changed version instead.