What is the default git diff tool(and merge tool)?
Where(and how) can I find it out?
I've never set any configuration for git difftool(nor mergetool) explicitly,
so git config --get difftool
shows nothing.
The git documentation says(https://git-scm.com/docs/git-difftool):
If the configuration variable
diff.tool
is not set,git difftool
will pick a suitable default.
How can I find out which one it has picked?
How does the algorithm for 'suitable' work?
Let me share the reason why I'm trying to find out the currently picked diff tool by my git:
I've met some weird diff result when I execute git diff
(I suspect BOM handling issue).
I'd like to question the vendor(e.g., p4merge
) about it,
but not sure if it is p4merge
, vimdiff
or anything else.
I expect there might be a command like git difftool --current
.
git difftool
will tell you what it's going to try.We can find the process in the
guess_merge_tool
function.list_merge_tool_candidates
sets up the list of$tools
. It assumes that if DISPLAY is not set you do not have a GUI which is incorrect on MacOS.Then it simply loops through them and picks the first one it finds an executable for using
type
.UPDATE
If you're having an issue with
git diff
that is withgit diff
notgit difftool
. I think there's some confusion about whatgit difftool
does, so here's a quick overview.git diff
does not use git-difftool.git difftool
does not pick the diff tool forgit diff
.git diff
has its own internal diff implementation. It can also use an external diff program, like GNU diff, by supplying--ext-diff
.When you run
git difftool
it picks an external diff program and runs it with three environment variables: $LOCAL, $REMOTE, and $MERGED. $LOCAL is a path to the old version of the file, $REMOTE to the new, and $MERGED to the name of the file so it can be displayed. That's about it. It has no relation togit diff
.We can see what
git difftool
does by adding to custom difftools to .gitconfig:git difftool -t echo
will show the environment variables.git difftool -t less
will look at the contents of the old and new versions of the files in theless
pager.If you're having a problem with
git diff
,git difftool
has nothing to do with it. Nor should p4merge nor vimdiff.