Is there a way to force git merge to always use an external merge tool?

572 Views Asked by At

Is there a way to configure git merge in such a way that conflict resolution always goes through an external merge tool?

I'm writing the configuration for semanticmerge and there are cases like this that are incorrectly handled by git but can be correctly solved by semanticmerge: * two developers added the same method on two different locations of the same file.

The problem is that git merge says the conflict is automatic so git mergetool can't be invoked.

Thanks.

1

There are 1 best solutions below

0
On

See the documentation of gitattributes. Deep down is an attribute called, "merge" that sets the merge method for matching files.

As such, for example, you could have a .gitattributes file in the root of the project that contains,

*.fancy merge filfre %O %A %B %L %P

which will use the filfre program to merge. It calls the program with

  • %O ancestor’s version temp file name
  • %A current version file name
  • %B the other branches' version temp file name
  • %L the conflict marker size
  • %P pathname in which the merged result will be stored

The merge driver is expected to overwrite %A with the result of the merge in the merge.

There is a section in that documentation, headed by "Defining a custom merge driver," that suggests, for globally setting the merge tool

[merge "filfre"]
    name = feel-free merge driver
    driver = filfre %O %A %B %L %P
    recursive = binary

placed in your git configuration, for example, .git/config or $HOME/.gitconfig.