Search code examples
gitdifftool

git difftool problem: not setting LOCAL, REMOTE variables


According to doc and various answers here git difftool will invoke the specified executable (usually a shell script) with environment variables LOCAL and REMOTE set to the file paths. But when I try, LOCAL and REMOTE are not set. I've tried the following test:

git config --global diff.tool mytest  
git config --global difftool.mytest.cmd mytest.sh  
git config --global difftool.prompt false  

with mytest.sh:

#!/bin/sh  
echo "LOCAL:$LOCAL REMOTE:$REMOTE"  

invoking:

git difftool --tool mytest <commitid> -- <path-to-file>  

output:

LOCAL: REMOTE:  

Any suggestions?


Solution

  • What the man page means is that difftool.<tool>.cmd can have $LOCAL and $REMOTE in its command-line. Those will be replaced with the relevant file paths. It isn't intended that those variables are exported into your environment.

    To demonstrate with an example, here's a re-worked version of your original setup.

    git config --global diff.tool mytest  
    git config --global difftool.mytest.cmd 'mytest.sh $LOCAL $REMOTE'
    git config --global difftool.prompt false