git-mergetool
做了很多,你可以
read the source to learn what it does
. 它只是一个shell脚本,您可以潜在地复制它的功能。但是利用所有这些工作并编写自己的合并工具要容易得多。
From the git-mergetool docs
...
git merge tool不是运行一个已知的合并工具程序,而是可以通过在配置变量mergetool..cmd中指定要调用的命令行进行自定义,以运行另一个程序。
使用此工具(通过-t或--tool选项或merge.tool配置变量)调用git mergetool时,将调用已配置的命令行,并将$BASE设置为包含合并公共基的临时文件的名称(如果可用);$LOCAL set为包含当前分支上文件内容的临时文件的名称;$REMOTE set为包含要合并的文件内容的临时文件的名称,$merged set为合并工具应向其写入合并解析结果的文件的名称。
编写一个小的shell脚本,把它放在您的路径中,并使其可执行。请务必以非零退出以指示合并失败。
$ cat ~/bin/show-git-mergefiles
#!/bin/sh
echo Base: $1
echo Local: $2
echo Remote: $3
echo Merged: $4
exit 1
然后将其添加到
.gitconfig
把环境变量传给它。
[mergetool "show-git-mergefiles"]
cmd = show-git-mergefiles $BASE $LOCAL $REMOTE $MERGED
trustExitCode = true
鲍勃是你父母的兄弟。
$ git mergetool -t show-git-mergefiles
Merging:
file2
Normal merge conflict for 'file2':
{local}: modified file
{remote}: modified file
Base: ./file2_BASE_84551
Local: ./file2_LOCAL_84551
Remote: ./file2_REMOTE_84551
Merged: file2
merge of file2 failed
Continue merging other unresolved paths [y/n]?
在此之前,考虑一下现有的合并工具是否符合您的需要。例如,
vimdiff
.
aldsfkalkd | aldsfkalkd | aldsfkalkd
ldfkjlj | ldfkjlj | ldfkjlj
another line | | feature line
---------------------| ---------------------| ----------------------
---------------------| ---------------------| ----------------------
---------------------| ---------------------| ----------------------
---------------------| ---------------------| ----------------------
~ | ~ | ~
~ | ~ | ~
~ | ~ | ~
./file2_LOCAL_82335 ./file2_BASE_82335 ./file2_REMOTE_82335
aldsfka
ldfk
<<<<<<< HEAD
another line
=======
feature line
>>>>>>> feature
~
~
~
~
file2