| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | MERGE STRATEGIES | 
 | 2 | ---------------- | 
 | 3 |  | 
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 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 |  | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 9 | resolve:: | 
 | 10 | This can only resolve two heads (i.e. the current branch | 
| Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 11 | and another branch you pulled from) using a 3-way merge | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 12 | algorithm. It tries to carefully detect criss-cross | 
 | 13 | merge ambiguities and is considered generally safe and | 
 | 14 | fast. | 
 | 15 |  | 
 | 16 | recursive:: | 
| Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 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 | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 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 mis-merges 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. | 
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 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 | + | 
 | 36 | This should not be confused with the 'ours' merge strategy, which does not | 
 | 37 | even look at what the other tree contains at all. It discards everything | 
 | 38 | the other tree did, declaring 'our' history contains all that happened in it. | 
 | 39 |  | 
 | 40 | theirs;; | 
 | 41 | This is opposite of 'ours'. | 
 | 42 |  | 
| Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 43 | patience;; | 
 | 44 | With this option, 'merge-recursive' spends a little extra time | 
 | 45 | to avoid mismerges that sometimes occur due to unimportant | 
 | 46 | matching lines (e.g., braces from distinct functions). Use | 
 | 47 | this when the branches to be merged have diverged wildly. | 
 | 48 | See also linkgit:git-diff[1] `--patience`. | 
 | 49 |  | 
 | 50 | ignore-space-change;; | 
 | 51 | ignore-all-space;; | 
 | 52 | ignore-space-at-eol;; | 
 | 53 | Treats lines with the indicated type of whitespace change as | 
 | 54 | unchanged for the sake of a three-way merge. Whitespace | 
 | 55 | changes mixed with other changes to a line are not ignored. | 
 | 56 | See 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 Hamano | 2db3e75 | 2010-09-03 21:33:06 | [diff] [blame] | 65 | renormalize;; | 
 | 66 | This runs a virtual check-out and check-in of all three stages | 
 | 67 | of a file when resolving a three-way merge. This option is | 
 | 68 | meant to be used when merging branches with different clean | 
 | 69 | filters or end-of-line normalization rules. See "Merging | 
 | 70 | branches with differing checkin/checkout attributes" in | 
 | 71 | linkgit:gitattributes[5] for details. | 
 | 72 |  | 
 | 73 | no-renormalize;; | 
 | 74 | Disables the `renormalize` option. This overrides the | 
 | 75 | `merge.renormalize` configuration variable. | 
 | 76 |  | 
| Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 77 | rename-threshold=<n>;; | 
 | 78 | Controls the similarity threshold used for rename detection. | 
 | 79 | See also linkgit:git-diff[1] `-M`. | 
 | 80 |  | 
| Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 81 | subtree[=<path>];; | 
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 82 | This option is a more advanced form of 'subtree' strategy, where | 
 | 83 | the strategy makes a guess on how two trees must be shifted to | 
 | 84 | match with each other when merging. Instead, the specified path | 
 | 85 | is prefixed (or stripped from the beginning) to make the shape of | 
 | 86 | two trees to match. | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 87 |  | 
 | 88 | octopus:: | 
| Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 89 | This resolves cases with more than two heads, but refuses to do | 
 | 90 | a complex merge that needs manual resolution. It is | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 91 | primarily meant to be used for bundling topic branch | 
 | 92 | heads together. This is the default merge strategy when | 
| Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 93 | pulling or merging more than one branch. | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 94 |  | 
 | 95 | ours:: | 
| Junio C Hamano | bf984de | 2009-11-23 06:11:19 | [diff] [blame] | 96 | This resolves any number of heads, but the resulting tree of the | 
 | 97 | merge is always that of the current branch head, effectively | 
 | 98 | ignoring all changes from all other branches. It is meant to | 
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 99 | be used to supersede old development history of side | 
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 100 | branches. Note that this is different from the -Xours option to | 
 | 101 | the 'recursive' merge strategy. | 
| Junio C Hamano | e6c9203 | 2008-03-19 09:24:34 | [diff] [blame] | 102 |  | 
 | 103 | subtree:: | 
 | 104 | This is a modified recursive strategy. When merging trees A and | 
 | 105 | B, if B corresponds to a subtree of A, B is first adjusted to | 
 | 106 | match the tree structure of A, instead of reading the trees at | 
 | 107 | the same level. This adjustment is also done to the common | 
 | 108 | ancestor tree. |