Merge Strategies

Git has several different methods to find a base commit, these methods are called "merge strategies".

  • Once Git finds a common base commit it will create a new "merge commit" that combines the changes of the specified merge commits.
  • Technically, a merge commit is a regular commit which just happens to have two parent commits.

when merging (and pulling), we can pass the -s flag to specify which merge strategy we want to use.

  • When not specified, Git will select the most appropriate based on the provided branches. merges can be either explicit or implicit
  • explicit means a new merge commit is created.
  • implicit means no new merge commit is made, and any evidence of a branch having existed is erased from history
    • This is accomplished either by fast-forward merges or rebases.

Strategy types

Specified with -s flag

  • ex. git merge -s ours feature-branch

Recursive

Operates on 2 heads. Therefore, it is the default when pulling/merging one branch.

Has additional sub-operation options, which allow us to auto-resolve conflicts, by accepting all changes in one HEAD version

  • ours - accept all "ours" versions of the HEADS
  • theirs - accept all "theirs" versions of the HEADS
  • patience - This option spends extra time to avoid mis-merges on unimportant matching lines. This options is best used when branches to be merged have extremely diverged.

Resolve

operates on 2 heads using 3-way merge algorithm.

Octopus

default when there are more than 2 heads.

Ours

The output merge result is always that of the current branch HEAD. The "ours" term implies the preference effectively ignoring all changes from all other branches. It is intended to be used to combine history of similar feature branches.

  • note: this should not be confused with the ours option of the Recursive Merge Strategy