ave*_*eek 21 git windows-xp diffmerge msysgit
我刚刚开始使用Git而且我可能错过了一些明显的东西,但是这里有:
我正在尝试整理一个包装脚本,我可以使用它来用DiffMerge替换内置的git diff.基于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%
Run Code Online (Sandbox Code Playgroud)
我将bat文件放在%GIT_INSTALL%/ cmd下并编辑了我的.gitconfig文件,如下所示:
[diff]
external = C:/Programs/git/cmd/git-diff-wrapper.bat
Run Code Online (Sandbox Code Playgroud)
如果我启动Git Bash并执行git diff HEAD HEAD~ - myfile
我收到一条消息File (\dev\null) not found- 鉴于我在Windows上并不奇怪.
按下,我启动了gitk,在Edit> Preferences下,我选择了相同的包装脚本.尝试特定文件的"外部差异"选项会产生神秘的错误消息Unknown Option "
很明显,我不知道我在做什么,所以任何帮助都会非常感激.
Wav*_*lor 15
我在互联网上寻找答案.我尝试了上面和其他地方的所有解决方案.我可以让合并部分工作而不是差异部分,反之亦然.所以我最终做的就是从我在互联网上获得的所有信息中将我自己的简单解决方案合并到一起.它不需要任何编辑您.gitconfig通常驻留在以下目录中的脚本C:\Documents and Settings\[username]您需要安装DiffMerge程序.
这是我的.gitconfig文件的相关摘录.您只需要编辑您的版本所在的路径DiffMerge.请注意,我在路径中使用旧的DOS 8.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
Run Code Online (Sandbox Code Playgroud)
git config --replace --global [options]如果您愿意,也可以使用命令进行设置.
这个简单的解决方案也适用于我.对于更新版本的DiffMerge(3.3.1),需要更改命令路径:
cmd = "C:/PROGRA~1/SourceGear/Common/DiffMerge/sgdm.exe ...etc..."
Run Code Online (Sandbox Code Playgroud)
我刚刚在使用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
Run Code Online (Sandbox Code Playgroud)
不要担心所有' \'go' /':它由调用外部diff工具的Git脚本完成.
我没有用DiffMerge测试它,但是使用WinMerge,它可以正常工作,无论是来自DOS会话还是Git Shell.
#!/bin/sh
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat
Run Code Online (Sandbox Code Playgroud)
(使用' -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
#### ADD THIS LINE BELOW
echo >&2 "editor is ${GIT_EDITOR:=vi} $@."
#### END ADDITION ABOVE
eval "${GIT_EDITOR:=vi}" '"$@"'
}
Run Code Online (Sandbox Code Playgroud)
您将看到使用什么参数调用哪个编辑器.
现在,关于"意外参数"部分:
当我用" /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"
Run Code Online (Sandbox Code Playgroud)
但我的钱宁愿是-title1"或-t1"形式:
-t1="Old Version" "$2" -t2="New Version" "$5"
Run Code Online (Sandbox Code Playgroud)
应该工作得很好.
小智 8
这对我有用,如下:
在~/.gitconfig:
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = \"C:/Program Files/git/cmd/git-diffmerge-merge.sh\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = false
Run Code Online (Sandbox Code Playgroud)
在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"
Run Code Online (Sandbox Code Playgroud)
信贷的一部分去http://therightstuff.de/2009/01/28/Setting-Up-SourceGear-DiffMerge-With-Git.aspx ;)