使用Git中的Winmerge来存档diff [英] use Winmerge inside of Git to file diff

查看:148
本文介绍了使用Git中的Winmerge来存档diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在git里面使用Winmerge来做Diffs?

解决方案

更新于2015年6月,6年后: git mergetool winmerge ,一个简单的 git config diff.tool winmerge 就足够了。

Git 2.5+(Q2,2015)现在已经意识到Winmerge是一个差异或合并工具!






原始答案(2009-2012)




第一部分(使用winmerge)在如何查看'git diff'输出与可视化差异程序?

  C:\myGitRepo> git config --replace --global diff.tool winmerge 
C:\myGitRepo> git config --replace --global difftool。 winmerge.cmdwinmerge.sh \$ LOCAL \\$ REMOTE \
C:\myGitRepo> git config --replac e --global difftool.prompt false

使用 winmerge.sh 存放在你的 PATH 的目录部分:

  #!/ bin / sh 
echo启动WinMergeU.exe:$ 1 $ 2
$ PROGRAMFILES / WinMerge / WinMergeU.exe-e -u -dl本地-dr远程$ 1 $ 2

(请参阅 WinMerge命令行选项

  git difftool 

现在会启动WinMerge。

如果您想要 git diff 来启动WinMerge,只需设定:

  set GIT_EXTERNAL_DIFF = winmerge.sh 






但是真正的附加价值来自于使用相同diff工具来在一个批次中显示所有差异,而不是按顺序显示它们,迫使您一次关闭一个文件的diff工具窗口。



2012年6月更新(2年半之后):

比较目录而不是逐个文件即将推出:

请参阅 [ANNOUNCE] Git 1.7.11.rc1


git difftool learn the<$ c在填充两个临时目录而不是运行之后,可以一次性生成外部diff工具,该工具可以比较两个目录层次结构每个文件对的外部工具实例

请参阅 difftool :teach difftool c>处理目录差异 ,然后回答 Git分支的目录比较了解更多详情。






原文difftool by directories script(2009年12月)

由于 Seba Illingworth 他的回答,脚本git-diffall.sh(也放在路径中)可以做到这一点:

 #!/ bin / sh 
git diff --name-only$ @|同时读取文件名;做
git difftool$ @ - 无提示$ filename&
完成

但只有打开 n n 文件(如果您尝试使用WinMerge的 -s 选项,则它将不起作用,因为临时文件也被difftool删除早期)






这就是为什么我喜欢 GitDiff.bat - 使用GI标识功能区分,可以让您查看在选择一个来检查其内部差异之前,有不同的文件列表。

我调整了它以仅使用DOS命令

  @echo off 
$ b $ setlocal

if%1== - ? (
echo GitDiff - 启用文件列表的区分,而不是必须连续
echo diff文件而不能返回到前一个文件
echo命令行选项被传递到git diff。
echo如果设置了GIT_FOLDER_DIFF,它将用来区分文件列表,默认为windff。
goto END


如果%GIT_DIFF_COPY_FILES% ==(
rd / s / q%TEMP%\GitDiff
mkdir%TEMP%\GitDiff
mkdir%TEMP%\GitDiff\old
mkdir%TEMP%\GitDiff\\\
ew

REM这个批处理文件将被git diff调用,这个env var指出是直接调用
REM还是在git diff
set GIT_DIFF_COPY_FILES = 1

set GIT_DIFF_OLD_FILES =%TEMP%\GitDiff\old
set GIT_DIFF_NEW_FILES =%TEMP%\GitDiff\\\
ew

set GIT_EXTERNAL_DIFF =%〜dp0 \GitDiff.bat
echo请等待,并在看到(END)时按下q n反向颜色...
调用git diff%*

(如果已定义)GIT_FOLDER_DIFF(
REM)使用GIT_FOLDER_DIFF的此命令只是出于某种原因不起作用。
%GIT_FOLDER_DIFF%TEMP%\GitDiff\old%TEMP%\GitDiff\\\
ew
转到END


如果存在%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\\\
ew
goto END


%ProgramFiles(x86)%\WinMerge \ WinMergeU.exe-r -e -dlLocal-drRemote%TEMP%\GitDiff\old%TEMP%\GitDiff\\\
ew
goto END


REM diff由git用7个参数调用:
REM路径old-file old-hex旧模式new-file新-hex新模式
copy%TEMP%\\ \\%〜nx2%GIT_DIFF_OLD_FILES%\%1
副本%5%GIT_DIFF_NEW_FILES%

:END

它不足以处理不同目录中具有相同名称的文件,但它为您提供属l想法是什么:

这里只有一个WinMerge会打开,文件列表有内部差异。您可以点击您要检查的那个,然后一个简单的 ESC 将关闭所有 WinMerge-diff 会话。


Is there a way to use Winmerge inside of git to do Diffs?

解决方案

Update June 2015, 6 years later:

As detailed in "git mergetool winmerge", a simple git config diff.tool winmerge will be enough.

Git 2.5+ (Q2, 2015) is now aware of Winmerge as a diff or merge tool!


Original answer (2009-2012)

(msysgit, 1.6.5, DOS session)

The first part (using winmerge) is described in "How do I view ‘git diff’ output with visual diff program?"

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 stored in a directory part of your PATH:

#!/bin/sh
echo Launching WinMergeU.exe: $1 $2
"$PROGRAMFILES/WinMerge/WinMergeU.exe" -e -u -dl "Local" -dr "Remote" "$1" "$2"

(see WinMerge Command-line options)

git difftool

will now launch WinMerge.
If you want git diff to launch WinMerge, just set:

set GIT_EXTERNAL_DIFF=winmerge.sh


But the real added value comes from the ability to use that same diff tool to present all differences in one batch instead of presenting them sequentially, forcing you to close the diff tool windows one file at a time.

Update June 2012 (2-and-a-half years later):

Comparing directories instead of file-by-file will be available soon:
See [ANNOUNCE] Git 1.7.11.rc1:

"git difftool" learned the "--dir-diff" option to spawn external diff tools that can compare two directory hierarchies at a time after populating two temporary directories, instead of running an instance of the external tool once per a file pair.

See "Patch difftool: teach difftool to handle directory diffs", and the answer "Directory comparison of Git branches" for more details.


Original difftool by directories script (December 2009)

As Seba Illingworth mentions in his answer, a script git-diffall.sh (also put in the path) can do just that:

#!/bin/sh
git diff --name-only "$@" | while read filename; do
    git difftool "$@" --no-prompt "$filename" &
done

But that only works by opening n windows for n files (if you try to use the -s option of WinMerge, it will not work because of the temp files being deleted by the difftool too early)


That is why I like the approach of GitDiff.bat - power-diffing with GI, which allows you to review the list of files with a difference, before selecting one to examine its internal differences.
I have tweaked it to use only DOS commands

@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.

这篇关于使用Git中的Winmerge来存档diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆