55

Possible Duplicate:
When would you use the different git merge strategies?

When git merges files I'm working on, I see:

Merge made by the 'recursive' strategy

What exactly is the recursive strategy? What other strategies are there (if any)? And what would be the benefit of using one over the other? Do different strategies have different performances? Or could two different strategies result in different merge results?

Community
  • 1
  • 1
K2xL
  • 9,730
  • 18
  • 64
  • 101
  • 6
    A good community wiki has been started here: http://stackoverflow.com/questions/366860/when-would-you-use-the-different-git-merge-strategies – Chris Missal Jan 09 '13 at 17:54
  • 3
    This is NOT a duplicate question. User is asking What are the algorithms, which is not the same as when would you use them. Algorithms are explained in some more detail at these places: RECURSIVE STRATEGY: http://codicesoftware.blogspot.com/2011/09/merge-recursive-strategy.html SUBTREE MERGE: http://git-scm.com/book/en/Git-Tools-Subtree-Merging @Chris Missal: No offense meant, but the community wiki comment above contains same link as the "Possible duplicate" box above, with less explanation, and is therefore just noise. – SteveS Aug 23 '13 at 18:29
  • 2
    My comment was posted before it was flagged as a duplicate. I was just trying to add some related information to the question. -_O – Chris Missal Aug 23 '13 at 19:53
  • 4
    This isn't a duplicate...the other question is when would you use them and it assumes you know what they are already. I want to know what the heck they are! – Nick Manning Jun 11 '15 at 21:52
  • This is duplicate question. Check this one https://stackoverflow.com/questions/55998614/merge-made-by-recursive-strategy – Jayprakash Dubey Jan 20 '20 at 07:17

1 Answers1

22

From git help merge:

   The merge mechanism (git-merge and git-pull commands) allows the
   backend merge strategies to be chosen with -s option. Some strategies
   can also take their own options, which can be passed by giving
   -X<option> arguments to git-merge and/or git-pull.

   resolve
       This can only resolve two heads (i.e. the current branch and
       another branch you pulled from) using a 3-way merge algorithm. It
       tries to carefully detect criss-cross merge ambiguities and is
       considered generally safe and fast.

   recursive
       This can only resolve two heads using a 3-way merge algorithm. When
       there is more than one common ancestor that can be used for 3-way
       merge, it creates a merged tree of the common ancestors and uses
       that as the reference tree for the 3-way merge. This has been
       reported to result in fewer merge conflicts without causing
       mis-merges by tests done on actual merge commits taken from Linux
       2.6 kernel development history. Additionally this can detect and
       handle merges involving renames. This is the default merge strategy
       when pulling or merging one branch.

       The recursive strategy can take the following options:

       ours
           This option forces conflicting hunks to be auto-resolved
           cleanly by favoring our version. Changes from the other tree
           that do not conflict with our side are reflected to the merge
           result.

           This should not be confused with the ours merge strategy, which
           does not even look at what the other tree contains at all. It
           discards everything the other tree did, declaring our history
           contains all that happened in it.

       theirs
           This is opposite of ours.

       subtree[=path]
           This option is a more advanced form of subtree strategy, where
           the strategy makes a guess on how two trees must be shifted to
           match with each other when merging. Instead, the specified path
           is prefixed (or stripped from the beginning) to make the shape
           of two trees to match.

   octopus
       This resolves cases with more than two heads, but refuses to do a
       complex merge that needs manual resolution. It is primarily meant
       to be used for bundling topic branch heads together. This is the
       default merge strategy when pulling or merging more than one
       branch.

   ours
       This resolves any number of heads, but the resulting tree of the
       merge is always that of the current branch head, effectively
       ignoring all changes from all other branches. It is meant to be
       used to supersede old development history of side branches. Note
       that this is different from the -Xours option to the recursive
       merge strategy.

   subtree
       This is a modified recursive strategy. When merging trees A and B,
       if B corresponds to a subtree of A, B is first adjusted to match
       the tree structure of A, instead of reading the trees at the same
       level. This adjustment is also done to the common ancestor tree.
dty
  • 18,795
  • 6
  • 56
  • 82
  • 46
    This still isn't very clear. Can anyone explain this a little clearer? – reneruiz Apr 04 '14 at 01:48
  • 14
    Man pages / help output are great if you understand the context and want a refresher. If you're unfamiliar with the topic, they can be obscure and unhelpful – Basic Sep 25 '15 at 22:14
  • 2
    The best explanation I could find is here http://stackoverflow.com/a/366940/536434 – briankip May 19 '17 at 09:17