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


当前回答

以下内容可以从这里的其他答案中获得,但对我来说,这很难(信息太多),所以这里是tkdiff的“只需键入”答案:

git difftool --tool=tkdiff <path to the file to be diffed>

你可以用你最喜欢的diffing工具的可执行文件名来代替tkdiff。只要(例如tkdiff),(或您最喜欢的diffing工具)在您的PATH中,它就会启动。

其他回答

这是一个适用于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

使用新的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中

如果您通过Cygwin执行此操作,则可能需要使用cygpath:

$ git config difftool.bc3.cmd "git-diff-bcomp-wrapper.sh \$LOCAL \$REMOTE"
$ cat git-diff-bcomp-wrapper.sh
#!/bin/sh
"c:/Program Files (x86)/Beyond Compare 3/BComp.exe" `cygpath -w $1` `cygpath -w $2`

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

.gitconfig的内容:

    [diff]
      tool = kdiff3

    [difftool]
       prompt = false

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