Question

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?

Was it helpful?

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

OTHER TIPS

This is the diff wrapper I've always used (with tkdiff):

#!/bin/sh

# diff is called with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode

tkdiff "$2" "$5"

Which uses parameters rather than $LOCAL and $REMOTE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top