我刚刚开始使用Git,很可能我忽略了一些显而易见的东西,但是下面是:
我正在尝试将一个包装器脚本组合在一起,可以用DiffMerge替换内置的git。基于SO上的这条线,我创建了以下批处理文件:
@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%我将bat文件放在%GIT_INSTALL%/cmd下面,并按如下方式编辑了我的.gitconfig文件:
[diff]
external = C:/Programs/git/cmd/git-diff-wrapper.bat如果我启动Git Bash并执行git diff HEAD~ - myfile
我收到了一条消息File (\dev\null) not found --考虑到我在Windows上,这并不令人惊讶。
接着,我启动了gitk,在Edit>Preferences下,我选择了相同的包装脚本。尝试特定文件的“外部diff”选项会给出神秘的错误消息Unknown Option "。
显然,我已经不知道我在做什么了,所以任何帮助都将是非常感谢的。
发布于 2009-04-23 21:49:57
我刚刚体验到了与用msysgit1.6.2.2将Notepad++设置为外部编辑器类似的体验。
关键是要意识到包装器不是DOS脚本,而是/bin/sh脚本。
因此,尝试放入".bat“(尽管它不是bat脚本,这里的扩展并不重要):
#!/bin/sh
# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
"C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" /title1="Old Version" "$2" /title2="New Version" "$5" | cat不要担心让所有的'\‘go '/':它是由调用外部diff工具的Git脚本完成的。
我没有在DiffMerge上测试它,但是在WinMerge上,它工作得很好,无论是从DOS会话还是从Git。
#!/bin/sh
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat(使用“-e”选项,我只需输入“ESC”就可以关闭并退出diff工具:这很好!)

极客在注释中添加:
添加了“
/bin/sh”标题,并再次尝试运行git。 这一次的错误是:Unexpected parameter 'C:/Docume~/avggeek/LOCALS~1/Temp/.diff_b08444有没有一种方法可以查看当我调用git diff时传递的参数是什么?
[1]实际上有一种方法可以查看参数被传递的是什么!
在C:\Program Files\Git\libexec\git-core\git-sh-setup文件中添加以下行:
git_editor() {
: "${GIT_EDITOR:=$(git config core.editor)}"
: "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
case "$GIT_EDITOR,$TERM" in
,dumb)
echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
echo >&2 "Please set one of these variables to an appropriate"
echo >&2 "editor or run $0 with options that will not cause an"
echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
exit 1
;;
esac
#### ADD THIS LINE BELOW
echo >&2 "editor is ${GIT_EDITOR:=vi} $@."
#### END ADDITION ABOVE
eval "${GIT_EDITOR:=vi}" '"$@"'
}您将看到调用哪个编辑器,使用什么参数。
现在,关于“意外参数”部分:
当我用"/e /ub“而不是"-e -ub”调用/e /ub时,我确实遇到了同样的错误,所以第一个问题是:
您确定"/title1“位不能用作"-title1”或"-t1“或"--title1”或"--t1“吗?这就是从第9章DiffMerge pdf文档的“命令行参数”中可以看到的。
如果不是,我怀疑一些双引号是为了正确地划分不同的参数。类似于:
"/title1="Old Version"" "$2" "/title2="New Version"" "$5"
or
"/title1=\"Old Version\"" "$2" "/title2=\"New Version\"" "$5"但我的钱宁愿放在"-title1“或"-t1”表格上:
-t1="Old Version" "$2" -t2="New Version" "$5"应该能正常工作。
发布于 2011-05-27 21:30:05
我在网上到处寻找答案。我在上面和其他地方尝试了所有的解决方案。我可以让合并部分工作,而不是diff部分,反之亦然。所以我最终所做的就是从我在互联网上得到的所有信息中黑出我自己的简单解决方案。它不需要任何脚本,只需要编辑您的.gitconfig (通常位于C:\Documents and Settings\[username]目录下),您需要已经安装了DiffMerge程序。
这是我的.gitconfig文件的相关摘录。您只需编辑到DiffMerge版本所在位置的路径即可。注意到我在path中使用了旧的DOS8.3格式
[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如果您愿意,也可以使用命令git config --replace --global [options]来设置它。
这个简单的解决方案也非常适合我。对于最新版本的DiffMerge (3.3.1),需要更改命令路径:
cmd = "C:/PROGRA~1/SourceGear/Common/DiffMerge/sgdm.exe ...etc..."发布于 2009-10-28 19:08:48
这对我来说是可行的,具体如下:
在~/.gitconfig中
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = \"C:/Program Files/git/cmd/git-diffmerge-merge.sh\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = false在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"部分功劳归于http://therightstuff.de/2009/01/28/Setting-Up-SourceGear-DiffMerge-With-Git.aspx ;)
https://stackoverflow.com/questions/780425
复制相似问题