1

In one of my projects, I have some files with a specific extension that I would like to merge using a specific tool of my own instead of git itself.

I know it is possible to specify custom merge and diff tools in .gitconfig this way :

[difftool "sourcetree"]
    cmd = 'C:/somepath/difftool.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
    cmd = 'C:/somepath/difftool.exe' \"$BASE\" \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"

That mergetool will be automatically call to resolve conflicts. However (unless I miss something) git will first try to merge files itself. What is wrong is that git will try to merge those files as regular text files (eg: code) and might miss the fact there is a conflict, or believe there are conflicts while there is not.

$ git merge foo
Auto-merging somefile //custom mergetool not called :(
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

I would like my merge tool to be always called once a file has to be merged (without git trying to merge it automatically on it's own). Is this possible ?

tigrou
  • 4,236
  • 5
  • 33
  • 59
  • Have you set an appropriate configuration in `.gitattributes`? – bk2204 Sep 21 '20 at 22:39
  • No. I'm reading about it right now. That is probably why it do not work. – tigrou Sep 21 '20 at 22:45
  • 1
    Potential duplicate of https://stackoverflow.com/questions/19113810/is-there-a-way-to-force-git-merge-to-always-use-an-external-merge-tool – zrrbite Sep 21 '20 at 23:02
  • Here's the documentation for a merge driver: https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver – John Szakmeister Sep 22 '20 at 00:22
  • Note that what Git does with `.gitattributes` is to run a *merge driver* on the conflicted file. That's different from what most users call a *merge tool*, though. – torek Sep 22 '20 at 01:49

0 Answers0