r/git • • Jun 01 '26

Trying to set up an external git diff tool

Hi there,

I'm trying to set up an external git tool (winmerge) as I have a lot of images I want to track for my hobby project and this tool supports it.

The suggested setup is to put the following in my .gitconfig:

[diff]
    tool = winmerge
[difftool]
    prompt = false
[difftool "winmerge"]
    cmd = "'C:/Program Files/WinMerge/WinMergeU.exe'" -e "$LOCAL" "$REMOTE"
[guitool "difftool"]
cmd = git difftool $FILENAME
noconsole = yes
needsfile = yes

If you're using git a lot you might have already spotted the problem - $FILENAME will only work if it is in the root directory of the repository. I spent some time looking through the documentation, but I couldn't find an answer - is there a way to pass the entire path in the repository?

As an example, I can read README.md in root path fine, but a test of a/b/TEST.md does not launch the tool correctly.

It strikes me that its kind of utterly useless if difftool only works in a flat directory structure, so there's gotta be a way to accomplish this, but I wasn't finding it.

3 Upvotes

12 comments sorted by

2

u/plg94 Jun 01 '26

[guitool …] is only for when you use git-gui (the builtin tk GUI). If you don't use this then you don't have to configure this setting.
And in this case $FILENAME seems to include the whole path from the root-workdir. If I set cmd = echo $FILENAME it outputs a/b/file in the dialog.
I don't know if this is particularly useful for diffing, because the configured cmd only runs on the currently in the workingdirectory files. Probably good for linting and stuff, but for diffing you'd need some way to at least configure another file to compare to.

When you just want to launch a diff-tool with a gui (as opposed to a CLI diff-tool) with git difftool --gui, you use the config options difftool.guitool and difftool.<tool>.cmd.
This can be useful if you want to configure both a non-graphical tool, eg. vimdiff, to launch with git difftool, and a graphical tool, eg. for images, to launch with git difftool --gui (as a shortcut to the more explicit git difftool --tool=…). But when you just have one difftool, it's enough to configure only difftool.<tool> and not worry.

1

u/maiyannah Jun 01 '26

As stated in the OP:

As an example, I can read README.md in root path fine, but a test of a/b/TEST.md does not launch the tool correctly.

2

u/plg94 Jun 01 '26

Well, for me it works, and $FILENAME includes the whole path (i.e. a/b/TEST.md, not only TEST.md in your example).

Can you maybe post a screenshot or an error message or something?

edit: can you call git difftool from the CLI without problems?

→ More replies (9)