How do I view 'git diff' output with my preferred diff tool/ viewer?

后端 未结 26 1877
清酒与你
清酒与你 2020-11-22 03:20

When I type git diff, I want to view the output with my visual diff tool of choice (SourceGear \"diffmerge\" on Windows). How do I configure git to do this?

26条回答
  •  广开言路
    2020-11-22 04:02

    Here's a batch file that works for Windows - assumes DiffMerge installed in default location, handles x64, handles forward to backslash replacement as necessary and has ability to install itself. Should be easy to replace DiffMerge with your favourite diff program.

    To install:

    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
    

提交回复
热议问题