5

I would like to force git to always merge using a (kind of) 3-way conflicts resolution. Moreover, I want to do it to the point of being able to choose single lines.

At the moment I am merging two branches. However, if possible, I'd like to know how to perform this task even when merging multiple branches.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Alexander
  • 23,432
  • 11
  • 63
  • 73

2 Answers2

2

Git tries to do 3-way merging by default (the recursive strategy for 2 heads, and the octopus strategy for 3+ heads).

If you want to see 3-way resolution options when manually merging, try setting the merge.conflictstyle config option to diff3.

(See the Configuration section of the git-merge man page for details on that option.)

Amber
  • 507,862
  • 82
  • 626
  • 550
0

The blog post "Five advanced Git merge techniques" does give even more details on the diff3 setting:

Turn diff3 conflicts using git config --global merge.conflictstyle diff3.
The diff3 conflict style adds an extra section between the new ||||||| marker and ======= markers, which indicates:

  • the original contents of the section,
  • with your changes above and
  • their (the branch that is being merged in's) changes below.

Even without a diff tool, the command git show can help:

When you are inside a merge, you can use a special :N: syntax, where N is a number, to automatically select one of the merge parents.

  • 1 selects the common base commit (the lower revision),
  • 2 selects your version ("mine"), and
  • 3 selects their version (the higher revision).

So git show :3:foobar.txt shows the upstream version of foobar.txt.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250