use Winmerge inside of Git to file diff

2019-01-05 07:23发布

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

8条回答
放我归山
2楼-- · 2019-01-05 07:57

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\<username>\.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.

查看更多
叼着烟拽天下
3楼-- · 2019-01-05 07:59
git config --global diff.tool winmerge
git config --global difftool.winmerge.cmd "\"$PROGRAMFILES\\WinMerge\\WinMergeU.exe\" -u -dl \"Local\" -dr \"Remote\" \"\$LOCAL\" \"\$REMOTE\""
git config --global difftool.prompt false

As per the WinMerge command line manual: "Parameters are prefixed with either a forward slash ( / ) or dash ( - ) character"

查看更多
Juvenile、少年°
4楼-- · 2019-01-05 08:08

Without configuration:

git difftool --tool winmerge

Assuming:

  • Winmerge is installed
  • Git for windows is installed, from "git version 2.12.0.windows1" or above (although earlier versions of git may have introduced the command).
查看更多
ら.Afraid
5楼-- · 2019-01-05 08:12

I faced trouble using the first part in 2 places and fixed it as follows

  1. The second command for setting up winmerge.cmd required an extra slash on cmdline (before $LOCAL and $REMOTE), else cygwin was substituting the variable in cmdline

    C:\myGitRepo>git config --replace --global difftool.winmerge.cmd "winmerge.sh \"\$LOCAL\" \"\$REMOTE\""
    
  2. changed the winmerge.sh file to (without this, was getting right-path-invalid error)

    #!/bin/sh
    echo Launching WinMergeU.exe: "$(cygpath -aw "$1")" "$(cygpath -aw "$2")"
    "$PROGRAMFILES/WinMerge/WinMergeU.exe" -e -ub -dl "Base" -dr "Mine" "$(cygpath -aw "$1")" "$(cygpath -aw "$2")"
    
查看更多
唯我独甜
6楼-- · 2019-01-05 08:13

Since the thread is getting confusing and bifurcated, here are consolidated instructions for the Directory Listing "--dir-diff" WinMerge method for msysgit Git Windows.

Step 1 - Create a file named winmerge.sh at a location accessible to your path (such as /home/bin/winmerge.sh) with following contents.

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

Step 2 - Type the following commands in Git Bash to instruct git to use winmerge.sh as difftool (these options get stored in /home/.gitconfig):

git config --replace --global diff.tool winmerge
git config --replace --global difftool.winmerge.cmd "winmerge.sh \"$LOCAL\" \"$REMOTE\""
git config --replace --global difftool.prompt false

Step 3 - Now you can test by typing the following command in Git Bash to start your WinMerge diff:

git difftool --dir-diff

Step 4 - For quicker access, create an alias for this command by adding this line to .bashrc in your home folder (or create .bashrc file with this line if file does not already exist):

alias diffdir='git difftool --dir-diff'

Step 5 - Now you can quickly see a diff in WinMerge just by typing the following command into Git Bash

diffdir
查看更多
你好瞎i
7楼-- · 2019-01-05 08:16

On windows you can do it this way:

1) Open .gitconfig file. It's located at your home directory: c:\users\username.gitconfig

2) Add the lines below. Pay attention to the single quotes wrapping the path to winmerge:

[diff]
    tool = winmerge
[difftool "winmerge"]
    cmd = "'C:/Program Files (x86)/WinMerge/WinMergeU.exe'" -e "$LOCAL" "$REMOTE"
[difftool]
    prompt = false
[merge]
    tool = winmerge
[mergetool "winmerge"]
    cmd = "'C:/Program Files (x86)/WinMerge/WinMergeU.exe'" \"$MERGED\" \"$REMOTE\"
[mergetool]
    keepBackup = false
    trustExitCode = false
查看更多
登录 后发表回答