编写git difftool时,该工具是否有办法知道要比较哪个文件? [英] When writing a git difftool, is there a way for the tool to know which file is being compared?

查看:110
本文介绍了编写git difftool时,该工具是否有办法知道要比较哪个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为该问题编写一个简单的difftool-验证仅Git提交移动线条-并有效...我想很好,但是有一个问题.

I tried writing a simple difftool for this question - Verify that Git commit only moves lines - and it works ... fine I guess, but there is one problem.

当要求它在两次提交之间进行比较时,如下所示:

When asking it to do a diff between two commits, like this:

git difftool -t OnlyMovedLines HEAD~1 HEAD

然后对于每个修改的文件,使用每个提交中的快照创建两个临时文件,然后调用该工具.

Then for each modified file, two temporary files gets created with the snapshots from each of the commits, and then the tool is invoked.

但是,这意味着该工具无法报告实际正在比较的文件,因为文件名可能是这样的:

This, however, means that the tool is unable to report which file is actually being diffed, as the filenames could be things like this:

C:\Users\lasse\AppData\Local\Temp/Ol8Kc9_a.txt
C:\Users\lasse\AppData\Local\Temp/WtSX78_a.txt

所以我的问题是,是否有任何方法可以向.gitconfig文件中的配置中添加更多内容,或者是否可以使用诸如环境变量之类的东西来告诉工具实际上是哪个文件比较?

So my question is this, is there any way for me to add more to the configuration in the .gitconfig file, or are there things like environment variables or whatnot, that can be used to tell the tool which file is actually being compared?

.gitconfig文件对于此特定工具如下所示:

The .gitconfig file looks like this for this particular tool:

[difftool "OnlyMovedLines"]
    cmd = 'D:\\path\\to\\netcoreapp3.1\\OnlyLinesMovedDiffTool.exe' $LOCAL $REMOTE

推荐答案

答案很简单.

.gitconfig配置缺少我的工具的第三个参数:

The .gitconfig configuration was missing a third parameter to my tool:

[difftool "OnlyMovedLines"]
    cmd = 'D:\\path\\to\\netcoreapp3.1\\OnlyLinesMovedDiffTool.exe' $LOCAL $REMOTE $BASE
                                                                                   ^^^^^

添加完之后,要比较的文件名将传递给我的程序.

After adding that, the name of the file being compared was passed to my program.

这篇关于编写git difftool时,该工具是否有办法知道要比较哪个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆