use Winmerge inside of Git to file diff

前端 未结 8 1110
清酒与你
清酒与你 2020-11-27 09:34

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

8条回答
  •  抹茶落季
    2020-11-27 09:54

    I was confused about why the solution was presented as a DOS batch file, as my Git installation came with a bash shell. I was also unable to get a DOS context running from bash, so I've attempted to adapt what was previously shared in a bash context.

    Since git diff appears to run the specified command once for each file, I split my solution into two bash scripts:

    First, configure gitprepdiff.sh to be the difftool as previously mentioned

    #!/bin/sh
    #echo ...gitprepdiff.sh
    cp -v $1 "$TMP/GitDiff/old/$2"
    cp -v $2 "$TMP/GitDiff/new"
    

    I also noted that the results of the git configure commands can be found and edited directly in C:\Users\\.gitconfigure

    gitdiff.sh is then run at the command-line where you would normally call git diff

    #!/bin/sh
    #echo Running gitdiff.sh...
    
    DIFFTEMP=$TMP/GitDiff
    
    echo Deleting and re-creating $DIFFTEMP...
    rm -rf $DIFFTEMP;
    mkdir $DIFFTEMP;
    
    echo Creating $DIFFTEMP/old...
    mkdir $DIFFTEMP/old;
    
    echo Creating $DIFFTEMP/new...
    mkdir $DIFFTEMP/new;
    
    git diff --name-only "$@" | while read filename; do
        git difftool "$@" --no-prompt "$filename";
    done
    
    "$PROGRAMFILES\WinMerge\WinMergeU.exe" -r -e -dl "Repository" -dr "Working" $LOCALAPPDATA\\Temp\\1\\GitDiff\\old $LOCALAPPDATA\\Temp\\1\\GitDiff\\new
    

    Also worth noting is that, on my installation, /tmp (in bash) mapped to %LOCALAPPDATA%\Temp\1\ (in Windows), so that's why I'm using the latter in my call to WinMerge.

提交回复
热议问题