Thursday, 26 January 2012

how to configure your git diff or merge tool

I recently wanted to change the diff setting for git to use diff merge in windows.
So I went googling around and I found a couple of very usefull Q/A on StackOverflow web site.

http://stackoverflow.com/questions/780425/how-do-i-setup-diffmerge-with-msysgit-gitk/783667#783667
In ~/.gitconfig:

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

if you also want to have the diff command using diffmerge then add the following two lines
[diff]
  tool=diffmerge
[difftool "diffmerge"]
  cmd = \"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe\"  \"$LOCAL\" \"$REMOTE\"

and use it like this
git difftool <file>
I know it might sound strange to have a .sh extension in windows but, it is not a typo. It's correct.



Created the file 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/Common/DiffMerge/sgdm.exe" --merge --result="$resultPath" "$localPath" "$basePath" "$remotePath" --title1="Mine" --title2="Merged: $4" --title3="Theirs"

and you're done!

No comments: