我刚刚在使用msysgit1.6.2.2时,遇到了与
将Notepad++设置为我的外部编辑器类似的问题。
关键是要意识到包装器不是DOS脚本,而是/bin/sh脚本。
所以尝试在你的“.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
不用担心将所有的“\
”转换为“/
”:这是通过Git脚本调用外部差异工具完成的。
我没有使用DiffMerge进行测试,但是使用WinMerge,无论从DOS会话还是Git Shell中,都可以正常工作。
#!/bin/sh
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat
(使用'
-e
'选项,我只需键入'
ESC
'就能关闭和退出diff 工具:这很好用!)
average_geek 在评论中补充道:
添加了 '/bin/sh
' 头并尝试再次运行 git diff。
这次的错误是:
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
echo >&2 "editor is ${GIT_EDITOR:=vi} $@."
eval "${GIT_EDITOR:=vi}" '"$@"'
}
您将看到调用哪个编辑器以及使用了什么参数。
现在,关于“意外的参数”部分:
当我使用“
/e /ub
”而不是“
-e -ub
”调用WinMergeU.exe时,我也遇到了同样类型的错误,因此第一个问题是:
您确定“
/title1
”不能作为“
-title1
”或“
-t1
”或“
--title1
”或“
--t1
”吗? 这是从DiffMerge的
pdf文档的第9章“命令行参数”中可以看到的内容。
如果不行,我怀疑需要加上双引号来正确地分隔不同的参数。类似这样:
"/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"
应该可以正常工作。