Search code examples
gitgit-diff

Setting a different diff tool dynamically at git diff calling


Is it possible to set a different diff tool dynamically when git diff is being called, even using shell variables?

I don't mean changing (persisting) git-config configurations, but changing it at "calling time", like as:

$ git diff oldbranch --diff-tool=path-to-my-diff-tool
$ GIT_DIFF_TOOL=path git diff oldbranch
$ export GIT_DIFF_TOOL=path; git diff oldbranch

Solution

  • Maybe not exactly, but you can get the exact same effect. (Maybe that is "exactly". :-) ) Instead of changing the persistent local configuration with git config diff.tool sometool, just change the configuration used for this Git command with, e.g., git -c diff.tool=sometool difftool ....

    Any change you could make permanently with git config name value, you can make temporarily with git -c name=value, for the duration of one Git command.

    Edit: note that git difftool itself has a -t tool argument, so this particular example is a bit silly. I'm just using it here to show how the -c name=value trick works.