当我们多人合作的时候,我们从远程仓库拉取更新出现冲突的时候,出现以下错误,这时候我们就需要手动修改冲突文件了。
$ git pull origin master
From github.com:xxx/xxx
* branch master -> FETCH_HEAD
……
Automatic merge failed; fix conflicts and then commit the result.
但是,默认修改冲突的编辑器的是vim,没有方便快捷的方法(也可能是我不够深入vim,要是有大神,麻烦指点下)
下面介绍的是如何修改mergetool。
先下载DiffMerge4.2.0.697、和Git工具(有的就不用了) 。
下载好了,建议将DiffMerge默认安装就好了,在Git的安装目录下的cmd文件夹中创建两个*.sh文件。
备注::如果DiffMerge不是默认安装,请自行修改下方sh文件中的目录路径。
1、git-difftool-diffmerge-wrapper.sh
# place this file in the Windows Git installation directory /cmd folder
# be sure to add the ../cmd folder to the Path environment variable
# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$1" "$2" | cat
2、git-mergetool-diffmerge-wrapper.sh
# place this file in the Windows Git installation directory /cmd folder
# be sure to add the ../cmd folder to the Path environment variable
# passing the following parameters to mergetool:
# local base remote merge_result
"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" "$1" "$2" "$3" --result="$4" --title1="Mine" --title2="Merge" --title3="Theirs"
之后,我们需要把这个目录添加到系统变量中去:
最后咯,我们就需要修改C:\Users\你的PC名称.gitconfig,在里面添加
[merge]
tool = diffmerge
[diff]
tool = diffmerge
[mergetool]
keepBackup = false
[mergetool "diffmerge"]
cmd = git-mergetool-diffmerge-wrapper.sh "$LOCAL" "$BASE" "$REMOTE" "$MERGED"
[difftool "diffmerge"]
cmd = git-difftool-diffmerge-wrapper.sh "$LOCAL" "$REMOTE"
大功告成~
当你发生冲突的时候就可以使用git mergetool来解决冲突,同时mergetool调用的是DiffMerge来解决冲突。
DiffMerge的有点在于右键有一键合并、追加等功能,而且界面简单。��