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