git difftool 问题:未设置 LOCAL、REMOTE 变量

发布于 2024-08-15 07:21:38 字数 576 浏览 3 评论 0原文

根据文档和此处的各种答案,git difftool 将调用指定的可执行文件(通常是 shell 脚本),并将环境变量 LOCAL 和 REMOTE 设置为文件路径。但当我尝试时,LOCAL 和 REMOTE 未设置。我尝试过以下测试:

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:  

有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微凉 2024-08-22 07:21:38

手册页的含义是 difftool..cmd 的命令行中可以包含 $LOCAL$REMOTE 。这些将被替换为相关的文件路径。这些变量无意导出到您的环境中。

为了通过示例进行演示,这里是原始设置的重新设计版本。

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

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
滥情稳全场 2024-08-22 07:21:38

这是我一直使用的 diff 包装器(使用 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"

它使用参数而不是 $LOCAL$REMOTE

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文