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


当前回答

如果你恰好已经有一个与文件类型相关的diff工具(比如,因为你安装了TortoiseSVN,它附带了一个diff查看器),你可以将常规的git diff输出通过管道发送到一个“temp”文件,然后直接打开该文件,而无需了解查看器:

git diff > "~/temp.diff" && start "~/temp.diff"

将其设置为全局别名效果更好:gitwhat

[alias]
    what = "!f() { git diff > "~/temp.diff" && start "~/temp.diff"; }; f"

其他回答

这是一个适用于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 OS X上,

git difftool -t diffuse

在Git文件夹中为我做这项工作。要安装漫反射,可以使用端口-

sudo port install diffuse

尝试此解决方案:

$ meld my_project_using_git

Meld了解Git,并提供最近更改的导航。

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

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

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

git difftool

如果您通过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`