Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
827 views
in Technique[技术] by (71.8m points)

git - How do I setup DiffMerge with msysgit / gitk?

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 ull) 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I looked all over the internet for the answer to this. I tried all of the solutions above and elsewhere. I could get the merge part to work and not the diff part or vice versa. So what I did eventually was to hack together my own simple solution from all the info I got on the internet which works for me. It does not require any scripts only that you edit your .gitconfig which normally resides in the following directory C:Documents and Settings[username] You'll need to have DiffMerge program installed already.

Here is relevant extract of my .gitconfig file. You'll just need to edit the path to where your version of of DiffMerge is. Note that I used the old DOS 8.3 format in the path

[diff]
    tool = diffm
[difftool "diffm"]
    cmd = "H:/PROGRA~1/SourceGear/DiffMerge/DiffMerge.exe $LOCAL $REMOTE"
    prompt = false

[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    cmd = "H:/PROGRA~1/SourceGear/DiffMerge/DiffMerge.exe --merge --result=$MERGED $LOCAL $BASE $REMOTE" 
    trustExitCode = false
    keepBackup = false

You can also set it up using the commands git config --replace --global [options] if you so wish.


This simple solution works perfectly for me, too. For more recent versions of DiffMerge (3.3.1), the command path needs to be changed:

    cmd = "C:/PROGRA~1/SourceGear/Common/DiffMerge/sgdm.exe ...etc..."

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...