6 年后,2015 年 6 月更新:
详见“git mergetool winmerge“, 一个简单的git config diff.tool winmerge
就足够了。
Git 2.5+(2015 年第二季度)现在知道 Winmerge 作为差异或合并工具!
原始答案(2009-2012)
(msysgit,1.6.5,DOS 会话)
第一部分(使用 winmerge)在“如何使用 Visual diff 程序查看“git diff”输出?"
C:\myGitRepo>git config --replace --global diff.tool winmerge
C:\myGitRepo>git config --replace --global difftool.winmerge.cmd "winmerge.sh \"$LOCAL\" \"$REMOTE\""
C:\myGitRepo>git config --replace --global difftool.prompt false
With winmerge.sh
存储在您的目录部分PATH
:
#!/bin/sh
echo Launching WinMergeU.exe: $1 $2
"$PROGRAMFILES/WinMerge/WinMergeU.exe" -e -u -dl "Local" -dr "Remote" "$1" "$2"
(see WinMerge 命令行选项)
git difftool
现在将启动 WinMerge。
如果你想git diff
要启动 WinMerge,只需设置:
set GIT_EXTERNAL_DIFF=winmerge.sh
但真正的附加值来自于使用相同的 diff 工具来在一批中呈现所有差异而不是按顺序显示它们,而是强制您一次关闭一个文件的 diff 工具窗口。
2012 年 6 月更新(两年半后):
很快将可以比较目录而不是逐个文件:
See [公告] Git 1.7.11.rc1:
"git difftool
“ 学到了 ”--dir-diff
“生成外部差异工具的选项可以比较两个目录层次结构填充两个临时目录后,而不是每个文件对运行一次外部工具的实例.
See "Patch difftool: teach difftool处理目录差异”,以及答案“Git分支目录比较“ 更多细节。
原始 difftool by 目录脚本(2009 年 12 月)
As 塞巴·伊林沃斯中提到他的回答,脚本 git-diffall.sh (也放在路径中)可以做到这一点:
#!/bin/sh
git diff --name-only "$@" | while read filename; do
git difftool "$@" --no-prompt "$filename" &
done
但这只有打开才能起作用n窗户为n文件(如果您尝试使用-s
WinMerge 的选项,它将不起作用,因为临时文件被 difftool 过早删除)
这就是为什么我喜欢这种方法GitDiff.bat - 使用 GI 进行功率比较,它允许您在选择一个文件来检查其内部差异之前查看有差异的文件列表。
我已经将其调整为仅使用 DOS 命令
@echo off
setlocal
if "%1" == "-?" (
echo GitDiff - enables diffing of file lists, instead of having to serially
echo diff files without being able to go back to a previous file.
echo Command-line options are passed through to git diff.
echo If GIT_FOLDER_DIFF is set, it is used to diff the file lists. Default is windff.
goto END
)
if "%GIT_DIFF_COPY_FILES%"=="" (
rd /s /q %TEMP%\GitDiff
mkdir %TEMP%\GitDiff
mkdir %TEMP%\GitDiff\old
mkdir %TEMP%\GitDiff\new
REM This batch file will be called by git diff. This env var indicates whether it is
REM being called directly, or inside git diff
set GIT_DIFF_COPY_FILES=1
set GIT_DIFF_OLD_FILES=%TEMP%\GitDiff\old
set GIT_DIFF_NEW_FILES=%TEMP%\GitDiff\new
set GIT_EXTERNAL_DIFF=%~dp0\GitDiff.bat
echo Please wait and press q when you see "(END)" printed in reverse color...
call git diff %*
if defined GIT_FOLDER_DIFF (
REM This command using GIT_FOLDER_DIFF just does not work for some reason.
%GIT_FOLDER_DIFF% %TEMP%\GitDiff\old %TEMP%\GitDiff\new
goto END
)
if exist "%ProgramFiles%\Beyond Compare 2\BC2.exe" (
set GIT_FOLDER_DIFF="%ProgramFiles%\Beyond Compare 2\BC2.exe"
"%ProgramFiles%\Beyond Compare 2\BC2.exe" %TEMP%\GitDiff\old %TEMP%\GitDiff\new
goto END
)
"%ProgramFiles(x86)%\WinMerge\WinMergeU.exe" -r -e -dl "Local" -dr "Remote" %TEMP%\GitDiff\old %TEMP%\GitDiff\new
goto END
)
REM diff is called by git with 7 parameters:
REM path old-file old-hex old-mode new-file new-hex new-mode
copy %TEMP%\%~nx2 %GIT_DIFF_OLD_FILES%\%1
copy %5 %GIT_DIFF_NEW_FILES%
:END
It is not robust enough to handle files with same names in different directories, but it gives you a general idea of what is possible:
Here only one WinMerge will open up, with the list of files having internal differences. You can click on the ones you want to examines, then a simple ESC will close the all WinMerge-diff
session.