blob: 595a3cf1a7118ba29a1d57d7fc17d233d89cd3d0 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231MERGE STRATEGIES
2----------------
3
Junio C Hamano1aa40d22010-01-21 17:46:434The 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'.
8
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
23causing mis-merges 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.
Junio C Hamano1aa40d22010-01-21 17:46:4328+
29The 'recursive' strategy can take the following options:
30
31ours;;
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.
35+
36This should not be confused with the 'ours' merge strategy, which does not
37even look at what the other tree contains at all. It discards everything
38the other tree did, declaring 'our' history contains all that happened in it.
39
40theirs;;
41This is opposite of 'ours'.
42
Junio C Hamano39c7a692010-10-27 06:08:5443patience;;
44With this option, 'merge-recursive' spends a little extra time
45to avoid mismerges that sometimes occur due to unimportant
46matching lines (e.g., braces from distinct functions). Use
47this when the branches to be merged have diverged wildly.
48See also linkgit:git-diff[1] `--patience`.
49
50ignore-space-change;;
51ignore-all-space;;
52ignore-space-at-eol;;
53Treats lines with the indicated type of whitespace change as
54unchanged for the sake of a three-way merge. Whitespace
55changes mixed with other changes to a line are not ignored.
56See also linkgit:git-diff[1] `-b`, `-w`, and
57`--ignore-space-at-eol`.
58+
59* If 'their' version only introduces whitespace changes to a line,
60 'our' version is used;
61* If 'our' version introduces whitespace changes but 'their'
62 version includes a substantial change, 'their' version is used;
63* Otherwise, the merge proceeds in the usual way.
64
Junio C Hamano2db3e752010-09-03 21:33:0665renormalize;;
66This runs a virtual check-out and check-in of all three stages
67of a file when resolving a three-way merge. This option is
68meant to be used when merging branches with different clean
69filters or end-of-line normalization rules. See "Merging
70branches with differing checkin/checkout attributes" in
71linkgit:gitattributes[5] for details.
72
73no-renormalize;;
74Disables the `renormalize` option. This overrides the
75`merge.renormalize` configuration variable.
76
Junio C Hamano39c7a692010-10-27 06:08:5477rename-threshold=<n>;;
78Controls the similarity threshold used for rename detection.
79See also linkgit:git-diff[1] `-M`.
80
Junio C Hamanod2179ef2010-10-22 04:12:1781subtree[=<path>];;
Junio C Hamano1aa40d22010-01-21 17:46:4382This option is a more advanced form of 'subtree' strategy, where
83the strategy makes a guess on how two trees must be shifted to
84match with each other when merging. Instead, the specified path
85is prefixed (or stripped from the beginning) to make the shape of
86two trees to match.
Junio C Hamano1a4e8412005-12-27 08:17:2387
88octopus::
Junio C Hamano1de75722009-03-26 08:39:3889This resolves cases with more than two heads, but refuses to do
90a complex merge that needs manual resolution. It is
Junio C Hamano1a4e8412005-12-27 08:17:2391primarily meant to be used for bundling topic branch
92heads together. This is the default merge strategy when
Junio C Hamano1de75722009-03-26 08:39:3893pulling or merging more than one branch.
Junio C Hamano1a4e8412005-12-27 08:17:2394
95ours::
Junio C Hamanobf984de2009-11-23 06:11:1996This resolves any number of heads, but the resulting tree of the
97merge is always that of the current branch head, effectively
98ignoring all changes from all other branches. It is meant to
Junio C Hamano1a4e8412005-12-27 08:17:2399be used to supersede old development history of side
Junio C Hamano1aa40d22010-01-21 17:46:43100branches. Note that this is different from the -Xours option to
101the 'recursive' merge strategy.
Junio C Hamanoe6c92032008-03-19 09:24:34102
103subtree::
104This is a modified recursive strategy. When merging trees A and
105B, if B corresponds to a subtree of A, B is first adjusted to
106match the tree structure of A, instead of reading the trees at
107the same level. This adjustment is also done to the common
108ancestor tree.