本文介绍了配置多个git mergetool和difftool,以便根据扩展名选择适当的工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行git difftool时,它递归地为所有文件运行默认的difftool.我写了一个脚本来根据扩展名选择合适的difftool,然后在脚本中调用git difftool -t mytool. difftool将所有参数重定向到新调用,这很好.但是,它也会以某种方式重定向所有文件名.因此,基本上,我的脚本变得无用,因为自定义difftool随所有更改的文件一起传递.

When I do git difftool, recursively it runs default difftool for all files. I wrote a script to choose appropriate difftool based on extension and I call like git difftool -t mytool in the script. difftool redirects all arguments to new call, which is good. However, it somehow redirects all file names as well. So basically, my script becomes useless since custom difftool is passed with all files that is changed.

我想做的是,将difftool限制为一个文件,或者至少使用一个文件而不是其余文件来调用我的diftool.基本上,这是我的脚本,我将其作为.gitconfig中的默认difftool.

What I want to do is, limit difftool to one file, or at least call my diftool with one file, not the rest. Basically, this is my script and I have this as the default difftool in .gitconfig.

if is_sbs $1 $2 ; then
    #custom difftool which is also defined in .gitconfig
    git dt -t rhapsody
else
    #for all files
    git dt -t kdiff3
fi

推荐答案

显然,git固有地通过管道传输了所有文件信息,并且脚本的参数中未显示该信息.我没有在.gitconfig中将其他diff工具定义为"difftool",而是使用适当的参数调用了可执行文件.完整的解决方案如下:

Apparently, git inherently pipes all file information and it is not shown in the arguments to the script. Instead of defining other diff tools as "difftool"s in .gitconfig, I've just made a call to the executable file with appropriate arguments. Complete solution is the following:

.gitconfig

[difftool]
    prompt = false
[mergetool]
    prompt = false
[difftool "selectiveDiff"]
    cmd = difftool.sh $LOCAL $REMOTE $BASE $MERGED
    keepBackup = false
[mergetool "selectiveMerge"]
    cmd = mergetool.sh $LOCAL $REMOTE $BASE $MERGED
    keepBackup = false

请记住,脚本应该在PATH中.创建目录并将其添加到您的PATH或使用PATH中已经存在的目录.

Please keep in mind that scripts should be in PATH. Either create a directory and add it to your PATH or use one that is already in PATH.

在某处定义变量

RHAPSODY_PATH="C:/Program Files (x86)/IBM/Rational/Rhapsody/8.0.5/DiffMerge.exe"
KDIFF3_PATH="C:/Program Files/KDiff3/kdiff3.exe"

difftool.sh

if is_sbs $1 $2 ; then
    "$RHAPSODY_PATH" -base $3 $1 $2 -xcompare
else
    "$KDIFF3_PATH" $1 $2
fi

mergetool.sh

if is_sbs $1 $2 ; then
    #DiffMerge.exe -base BASE FILE1 FILE2 -out OUTPUT -xmerge
    "$RHAPSODY_PATH" -base $3 $1 $2 -out $4 -xmerge
else
    #kdiff3 BASE FILE1 FILE2 -o OUTPUT
    "$KDIFF3_PATH" $3 $1 $2 -o $4
fi

它将在调用时选择正确的差异和合并工具.

It will choose the right diff and merge tool upon calls.

这篇关于配置多个git mergetool和difftool,以便根据扩展名选择适当的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 22:33