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