如何让DiffMerge配置为在Windows 7或Windows 2012上使用Git?

时间:2012-12-13 20:36:02

标签: git diffmerge

所以我看到了一些关于让DiffMerge成为git的mergetooldifftool的问题。从本质上讲,它归结为在PATH.gitconfig中使用DiffMerge(sgdm.exe),如下所示:

[diff]
    tool = DiffMerge
[difftool "DiffMerge"]
    cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' "$LOCAL" "$REMOTE"
[merge]
    tool = DiffMerge
[mergetool "DiffMerge"]
    cmd = 'C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe' -merge -result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"
    trustExitCode = true
    keepBackup = false

当我运行git difftool file1 file2时,没有任何反应。没有错误代码,也没有启动DiffMerge。从Git Bash和Windows命令行,我可以运行sgdm file1 file2并启动DiffMerge。

我已将cmd中的.gitconfig修改为没有路径或扩展名(例如sgdm),但仍无济于事。

有没有人遇到过这个?有什么明显的东西我不见了吗?我觉得我错过了一些明显的东西。

6 个答案:

答案 0 :(得分:13)

我使用SourceGear DiffMerge的.gitconfig是:

[mergetool "diffmerge"]
cmd = \"C:\\program files\\sourcegear\\common\\diffmerge\\sgdm.exe\" --merge --result=$MERGED $LOCAL $BASE $REMOTE

(显然,如果你喜欢另一方,请翻转$LOCAL$REMOTE。)

答案 1 :(得分:5)

这对我来说很有效。 (Windows 7,Git的最新版本。)

确保sgdm.exe位于环境路径中。

[diff]
    tool = sgdm
[difftool "diffmerge"]
    cmd = sgdm $LOCAL $REMOTE
[merge]
    tool = sgdm
[mergetool "diffmerge"]
    cmd = sgdm --merge --result=$MERGED $LOCAL $BASE $REMOTE
    trustexitcode = false
[difftool "sgdm"]
    cmd = sgdm $LOCAL $REMOTE
[mergetool "sgdm"]
    trustexitcode = false
    cmd = sgdm --merge --result=$MERGED $LOCAL $MERGED $REMOTE --title1=Mine --title2='Merged: $MERGED' --title3=Theirs

答案 2 :(得分:2)

This为我工作:

C:\> git config --global diff.tool diffmerge
C:\> git config --global difftool.diffmerge.cmd
    "C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe
        \"$LOCAL\" \"$REMOTE\""

C:\> git config --global merge.tool diffmerge
C:\> git config --global mergetool.diffmerge.trustExitCode true
C:\> git config --global mergetool.diffmerge.cmd 
    "C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe
        /merge /result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\""

答案 3 :(得分:1)

以下为我工作 -

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe "$LOCAL" "$REMOTE"'
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.diffmerge.cmd 'C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe -merge -result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"'

答案 4 :(得分:0)

此配置适用于Git 1.7.9和Windows 7 64位。我的出发点是Pro Git书http://git-scm.com/book/en/Customizing-Git-Git-Configuration。对Windows和Mac的更改是a)对于diff,只是替换/用\\并且在包含空格的路径周围放置引号b)用于合并参数与您的相同但是带引号。因此:

<强>的.gitconfig

[merge]
     tool = extMerge
[mergetool "extMerge"]
    cmd = extMerge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
    trustExitCode = false
[diff]
    external = extDiff

PATH上的两个脚本文件

<强> extMerge

#!/bin/sh
"C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" "-merge" "-result=$4" "$2" "$1" "$3"

<强> extDiff

#!/bin/sh
[ $# -eq 7 ] && "C:\\Program Files\\SourceGear\\Common\\DiffMerge\\sgdm.exe" "$2" "$5"

答案 5 :(得分:0)

当其他人没有做到时,这个人为我做了:

[core]
    autocrlf = false
[user]
    email = XYZ
    name = ABC
[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    trustExitCode = true
    cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe --merge --result=$MERGED $LOCAL $BASE $REMOTE
[mergetool]
    keepBackup = false
[difftool "diffmerge"]
    cmd = C:/Program\\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"
[diff]
    tool = diffmerge
[push]
    default = matching