Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set difftool/mergetool for a specific file extension in Git?

Is it possible to set a custom tool for merging files with a specific extension in Git?

Thanks for any pointers!

Update

I wasn't able to come up with any better solution than defining a custom difftool and calling it by hand as @jarodeells suggested:

[diff]
    tool = mydiff
[difftool "mydiff"]
    cmd="script.sh \"$LOCAL\" \"$REMOTE\""

Then calling it explicitly:

$ git difftool -t mydiff someFileWith.ext
like image 945
rlegendi Avatar asked Sep 10 '12 17:09

rlegendi


People also ask

How do I use Mergetool meld in git?

git mergetool allows you to use a GUI merge program (i.e. Meld) to resolve the merge conflicts that have occurred during a merge. Like difftool you can set the GUI program on the command line using -t <tool> / --tool=<tool> but, as before, it makes more sense to configure it in your . gitconfig file.

How do I use git Difftool?

Usage. Run Git Difftool: Diff File from the Command Palette or use ⌥⌃D to diff the currently open file. Run Git Difftool: Diff Project from the Command Palette or use ⌃⇧D to diff the whole project.


2 Answers

Update: See @Ackdari comments below. The external tool doesn't have to be command-line based. I'm not sure how git uses binary = True when an external tool is used, but I suspect it might be needed for all flows to work.

If your external diff tool* is command-line only (no GUI), You can use the built-in gitattributes for this:

in .gitconfig add:

[diff "my_diff"]
    command = Tools/csv_diff
    binary = true # Not sure this is required.

and in .gitattributes (either global or per repository, see here) add:

*.csv diff=my_diff

[*] The command for the external diff tool will be called by git with the 7 parameters detailed under GIT_EXTERNAL_DIFF in the manual here.

like image 181
OmerB Avatar answered Nov 29 '22 08:11

OmerB


If not already supported, install a shell script that keys off the extension and calls the correct merge tool.

like image 24
jarodeells Avatar answered Nov 29 '22 06:11

jarodeells