Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | MERGE STRATEGIES |
| 2 | ---------------- |
| 3 | |
Junio C Hamano | 3214e5f | 2014-03-25 19:54:38 | [diff] [blame] | 4 | The merge mechanism (`git merge` and `git pull` commands) allows the |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 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>` |
Junio C Hamano | 3214e5f | 2014-03-25 19:54:38 | [diff] [blame] | 7 | arguments to `git merge` and/or `git pull`. |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 8 | |
Junio C Hamano | 7a031e5 | 2021-08-30 23:54:25 | [diff] [blame] | 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`. |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 24 | + |
Junio C Hamano | 7a031e5 | 2021-08-30 23:54:25 | [diff] [blame] | 25 | The 'ort' strategy can take the following options: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 26 | |
| 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 |
Junio C Hamano | 8ef91f3 | 2019-12-01 22:58:27 | [diff] [blame] | 30 | conflict with our side are reflected in the merge result. |
Junio C Hamano | a3cfb76 | 2012-09-15 05:32:14 | [diff] [blame] | 31 | For a binary file, the entire contents are taken from our side. |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 32 | + |
| 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. |
| 36 | |
| 37 | theirs;; |
Junio C Hamano | f088858 | 2017-09-28 06:34:39 | [diff] [blame] | 38 | This is the opposite of 'ours'; note that, unlike 'ours', there is |
Junio C Hamano | 8100016 | 2018-03-21 19:54:50 | [diff] [blame] | 39 | no 'theirs' merge strategy to confuse this merge option with. |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 40 | |
Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 41 | ignore-space-change;; |
| 42 | ignore-all-space;; |
| 43 | ignore-space-at-eol;; |
Junio C Hamano | 4886c77 | 2017-11-27 03:33:28 | [diff] [blame] | 44 | ignore-cr-at-eol;; |
Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 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. |
Junio C Hamano | 4886c77 | 2017-11-27 03:33:28 | [diff] [blame] | 48 | See also linkgit:git-diff[1] `-b`, `-w`, |
| 49 | `--ignore-space-at-eol`, and `--ignore-cr-at-eol`. |
Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 50 | + |
| 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 Hamano | 2db3e75 | 2010-09-03 21:33:06 | [diff] [blame] | 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. |
| 64 | |
| 65 | no-renormalize;; |
| 66 | Disables the `renormalize` option. This overrides the |
| 67 | `merge.renormalize` configuration variable. |
| 68 | |
Junio C Hamano | 76df4f7 | 2016-02-26 22:13:10 | [diff] [blame] | 69 | find-renames[=<n>];; |
| 70 | Turn on rename detection, optionally setting the similarity |
Junio C Hamano | 309465b | 2018-05-30 06:32:59 | [diff] [blame] | 71 | threshold. This is the default. This overrides the |
| 72 | 'merge.renames' configuration variable. |
Junio C Hamano | 76df4f7 | 2016-02-26 22:13:10 | [diff] [blame] | 73 | See also linkgit:git-diff[1] `--find-renames`. |
| 74 | |
Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 75 | rename-threshold=<n>;; |
Junio C Hamano | 76df4f7 | 2016-02-26 22:13:10 | [diff] [blame] | 76 | Deprecated synonym for `find-renames=<n>`. |
Junio C Hamano | 39c7a69 | 2010-10-27 06:08:54 | [diff] [blame] | 77 | |
Junio C Hamano | d2179ef | 2010-10-22 04:12:17 | [diff] [blame] | 78 | subtree[=<path>];; |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 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. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | |
Junio C Hamano | 7a031e5 | 2021-08-30 23:54:25 | [diff] [blame] | 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. |
| 98 | + |
| 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: |
| 102 | |
| 103 | patience;; |
| 104 | Deprecated synonym for `diff-algorithm=patience`. |
| 105 | |
| 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. |
| 113 | |
| 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`. |
| 118 | |
| 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. |
| 124 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 125 | octopus:: |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 126 | This resolves cases with more than two heads, but refuses to do |
| 127 | a complex merge that needs manual resolution. It is |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 128 | primarily meant to be used for bundling topic branch |
| 129 | heads together. This is the default merge strategy when |
Junio C Hamano | 1de7572 | 2009-03-26 08:39:38 | [diff] [blame] | 130 | pulling or merging more than one branch. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 131 | |
| 132 | ours:: |
Junio C Hamano | bf984de | 2009-11-23 06:11:19 | [diff] [blame] | 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 |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 136 | be used to supersede old development history of side |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 137 | branches. Note that this is different from the -Xours option to |
| 138 | the 'recursive' merge strategy. |
Junio C Hamano | e6c9203 | 2008-03-19 09:24:34 | [diff] [blame] | 139 | |
| 140 | subtree:: |
Junio C Hamano | 7a031e5 | 2021-08-30 23:54:25 | [diff] [blame] | 141 | This is a modified `ort` strategy. When merging trees A and |
Junio C Hamano | e6c9203 | 2008-03-19 09:24:34 | [diff] [blame] | 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. |
Junio C Hamano | cf77b04 | 2013-12-17 23:54:21 | [diff] [blame] | 146 | |
Junio C Hamano | 7a031e5 | 2021-08-30 23:54:25 | [diff] [blame] | 147 | With the strategies that use 3-way merge (including the default, 'ort'), |
Junio C Hamano | cf77b04 | 2013-12-17 23:54:21 | [diff] [blame] | 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. |