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.toolis not set,git difftoolwill 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 difftoolwill tell you what it's going to try.We can find the process in the
guess_merge_toolfunction.list_merge_tool_candidatessets 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 diffthat is withgit diffnotgit difftool. I think there's some confusion about whatgit difftooldoes, so here's a quick overview.git diffdoes not use git-difftool.git difftooldoes not pick the diff tool forgit diff.git diffhas its own internal diff implementation. It can also use an external diff program, like GNU diff, by supplying--ext-diff.When you run
git difftoolit 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 difftooldoes by adding to custom difftools to .gitconfig:git difftool -t echowill show the environment variables.git difftool -t lesswill look at the contents of the old and new versions of the files in thelesspager.If you're having a problem with
git diff,git difftoolhas nothing to do with it. Nor should p4merge nor vimdiff.