我刚刚经历了与setting Notepad++ as my external editor with msysgit1.6.2.2 有点相似的经历。
关键是要意识到包装器不是 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
不用担心让所有的 '\' 变成 '/':这是由 Git 脚本调用外部 diff 工具完成的。
我没有使用 DiffMerge 对其进行测试,但使用 WinMerge,无论是从 DOS 会话还是 Git Shell 都可以正常工作。
#!/bin/sh
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat
(使用 '-e' 选项,我只需输入 'ESC' 即可关闭并退出 diff 工具:效果很好!)
average_geek 在 cmets 中添加:
添加了“/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
#### ADD THIS LINE BELOW
echo >&2 "editor is ${GIT_EDITOR:=vi} $@."
#### END ADDITION ABOVE
eval "${GIT_EDITOR:=vi}" '"$@"'
}
您将看到正在调用哪个编辑器,使用什么参数。
现在,关于“意外参数”部分:
当我用“/e /ub”而不是“-e -ub”调用 WinMergeU.exe 时,我确实遇到了同样的错误,所以第一个问题是:
您确定“/title1”位不能用作“-title1”或“-t1”或“--title1”或“--t1”吗?这就是Is可以从chapter 9 "Command Lines Arguments" of the pdf documentation of DiffMerge看到的。
如果不是,我怀疑一些双引号是为了正确分隔不同的参数。比如:
"/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"
应该可以正常工作。