views:

2820

answers:

3

I've just started using Git and it's possible I've missed something obvious, but here goes:

  • I'm using msysgit 1.6.2.2 on Windows XP
  • While installing, I picked option 1 to "Use Git Bash only"

I'm trying to put together a wrapper script that I can use to replace the built in git diff with DiffMerge. Based on this thread on SO, I created the following batch file:

@echo off
REM ---- Switch forward slashes to back slashes ----
set oldW=%2
set oldW=%oldW:/=\%
set newW=%5
set newW=%newW:/=\%

REM ---- Launch DiffMerge ----
"C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" /title1="Old Version" %oldW% /title2="New Version" %newW%

I placed the bat file under %GIT_INSTALL%/cmd and edited my .gitconfig file as follows:

[diff]
external = C:/Programs/git/cmd/git-diff-wrapper.bat

If i launch Git Bash and execute git diff HEAD HEAD~ -- myfile

I get a message File (\dev\null) not found - which given I'm on Windows is not surprising.

Pressing on, I launched gitk and under Edit>Preferences, I chose the same wrapper script. Trying the "external diff" option for a particular file gives the cryptic error message Unknown Option "

Clearly, I have no idea what I'm doing anymore so any help would be much appreciated.

+4  A: 
VonC
I added the `/bin/sh` header and tried running git diff again. This time the error is: Unexpected parameter 'C:/Docume~`/avggeek/LOCALS~1/Temp/.diff_b08444Is there a way to see what are the parameters getting passed when I call `git diff`?
average_geek
+1  A: 

VonC - switching to -t1 and -t2 fixed the errors. Diffmerge now works for git bash :)

After a little bit of poking at the gitk patch that added External Diff support, I realized that it's calling an External Diff program directly with the two files as arguments. So I modified gitk>Edit>Preferences and put the following command directly into the External Diff Tool option:

"C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" -t1="Old Version" -t2="New Version"

Now I have DiffMerge working for gitk too :-)

average_geek
Awesome, it did work! And thank you for the feedback on gitk. +1
VonC
+2  A: 

This works for me with as follows:

In ~/.gitconfig:

[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = \"C:/Program Files/git/cmd/git-diffmerge-merge.sh\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = false

In C:\Program Files\Git\cmd\git-diffmerge-merge.sh:

#!/bin/sh

localPath="$2"
basePath="$1"
remotePath="$3"
resultPath="$4"

if [ ! -f $basePath ]
then
    basePath="~/diffmerge-empty"
fi

"C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe" --merge --result="$resultPath" "$localPath" "$basePath" "$remotePath" --title1="Mine" --title2="Merged: $4" --title3="Theirs"

Part of the credit goes to http://therightstuff.de/2009/01/28/Setting-Up-SourceGear-DiffMerge-With-Git.aspx ;)

Max