gpt4 book ai didi

git - 在 Git 中使用 Winmerge 来归档差异

转载 作者:IT王子 更新时间:2023-10-29 01:24:27 24 4
gpt4 key购买 nike

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

最佳答案

2015 年 6 月更新,6 年后:

如“git mergetool winmerge”中所述,一个简单的 git config diff.tool winmerge 就足够了。

Git 2.5+(2015 年第 2 季度)现在将 Winmerge 识别为差异或 merge 工具!


原始答案(2009-2012)

(msysgit,1.6.5,DOS session )

第一部分(使用 winmerge)在“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

winmerge.sh 存储在 PATH 的目录部分:

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

(参见 WinMerge Command-line options)

git difftool

现在将启动 WinMerge。
如果您希望 git diff 启动 WinMerge,只需设置:

set GIT_EXTERNAL_DIFF=winmerge.sh

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

2012 年 6 月更新(两年半后):

比较目录而不是逐个文件将很快可用:
参见 [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.

有关详细信息,请参阅“ Patch difftool: teach difftool to handle directory diffs ”和答案“Directory comparison of Git branches”。


目录脚本的原始 difftool(2009 年 12 月)

作为Seba Illingworthhis answer 中提到,脚本 git-diffall.sh(也放在路径中)可以做到这一点:

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

但这只能通过为 n 个文件打开 n 个窗口来实现(如果您尝试使用 WinMerge 的 -s 选项,它将由于 difftool 过早删除临时文件而无法工作)


这就是为什么我喜欢 GitDiff.bat - power-diffing with 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

它不够健壮,无法处理不同目录中具有相同名称的文件,但它可以让您大致了解可能发生的情况:
这里只会打开一个 WinMerge,其中包含内部差异的文件列表。您可以单击要检查的那些,然后一个简单的 ESC 将关闭所有 WinMerge-diff session 。

关于git - 在 Git 中使用 Winmerge 来归档差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1881594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com