当我键入gitdiff时,我想用我选择的可视化diff工具(Windows上的SourceGear“diffmerge”)查看输出。如何配置git以执行此操作?


当前回答

使用新的gitdifftool,只需将其添加到.gitconfig文件中即可:

[diff]
    tool = any-name
[difftool "any-name"]
    cmd = "\"C:/path/to/my/ext/diff.exe\" \"$LOCAL\" \"$REMOTE\""

也可以选择添加:

[difftool]
    prompt = false

还可以查看diffall,这是我编写的一个简单脚本,用于扩展串行打开每个文件的烦人(IMO)默认diff行为。

Windows上的全局.gitconfig位于%USERPROFILE%\.gitconfig中

其他回答

对以前的伟大答案的简短总结:

git difftool --tool-help
git config --global diff.tool <chosen tool>
git config --global --add difftool.prompt false

然后通过键入(也可以选择指定文件名)使用它:

git difftool

这是一个适用于Windows的批处理文件-假设DiffMerge安装在默认位置,处理x64,根据需要处理前向反斜杠替换,并能够自行安装。应该很容易用你喜欢的diff程序替换DiffMerge。

要安装:

gitvdiff --install 

gitvdiff.bat:

@echo off

REM ---- Install? ----
REM To install, run gitvdiff --install

if %1==--install goto install



REM ---- Find DiffMerge ----

if DEFINED ProgramFiles^(x86^) (
    Set DIFF="%ProgramFiles(x86)%\SourceGear\DiffMerge\DiffMerge.exe"
) else (
    Set DIFF="%ProgramFiles%\SourceGear\DiffMerge\DiffMerge.exe"
)



REM ---- Switch forward slashes to back slashes ----

set oldW=%2
set oldW=%oldW:/=\%
set newW=%5
set newW=%newW:/=\%


REM ---- Launch DiffMerge ----

%DIFF% /title1="Old Version" %oldW% /title2="New Version" %newW%

goto :EOF



REM ---- Install ----
:install
set selfL=%~dpnx0
set selfL=%selfL:\=/%
@echo on
git config --global diff.external %selfL%
@echo off


:EOF

如果你在Mac上,并且有Xcode,那么你已经安装了FileMerge。终端命令是opendiff,因此您可以执行以下操作:

git difftool -t opendiff

这在Windows 7上适用。不需要中间sh脚本

.gitconfig的内容:

    [diff]
      tool = kdiff3

    [difftool]
       prompt = false

    [difftool "kdiff3"]
      path = C:/Program Files (x86)/KDiff3/kdiff3.exe
      cmd = "$LOCAL" "$REMOTE"

Windows/MSYS Git解决方案

看完答案后,我发现了一种更简单的方法,只需要更改一个文件。

使用参数2和5创建一个批处理文件来调用diff程序。此文件必须位于您路径中的某个位置。(如果您不知道它在哪里,请将其放在C:\windows中。)调用它,例如,“gitdiff.bat”。我的是:@回声消失REM这是gitdiff.bat“C:\Program Files\WinMerge\WinMergeU.exe”%2%5将环境变量设置为指向批处理文件。例如:GIT_EXTERNAL_DIFF=gitdiff.bat。或通过PowerShell键入GIT-config--globaldiff.EXTERNAL gitdiff.bat。重要的是不要使用引号或指定任何路径信息,否则将无法工作。这就是为什么gitdiff.bat必须在您的路径中。

现在,当您键入“gitdiff”时,它将调用外部diff查看器。