如果出现合并冲突,如何让git自动打开mergetool? [英] How do I make git automatically open the mergetool if there is a merge conflict?
本文介绍了如果出现合并冲突,如何让git自动打开mergetool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让git为任何合并冲突自动运行 git mergetool
?这应该适用于所有合并,使用 merge
, rebase
, pull
等等。
解决方案
这可能是也可能不是可接受的解决方法。
$ b $
在〜/ .bashrc
中创建一个函数:
git()
{
if [[$ 1 ==merge]] || [[$ 1 ==rebase]] || [[$ 1 ==pull]];那么
命令git$ @
rc = $?
if [[$ rc == 1]];然后
回声有冲突,更好地运行git-mergetool !!!
#可能有其他一些条件返回'1',
#如果你可以添加另一个这样的检查:
#if grep冲突$(git --git-dir) / MERGE_MSG;
命令git mergetool
fi
else
命令git$ @
fi
}
合并时不调用Mergetool:
$ git合并non_conflicting_branch
通过'递归'策略进行合并。
bar | 0
1个文件已更改,0个插入(+),0个删除( - )
创建模式100644栏
当存在冲突时调用Mergetool:
$ git merge conflicting_branch
自动合并foo
CONFLICT(内容):在foo中合并冲突
自动合并失败;修复冲突,然后提交结果。
有冲突,更好运行git-mergetool !!!
Mergetool不会被其他错误调用:
$ git merge adasds
fatal:adasds - 不是我们可以合并的东西
How do I make git automatically run git mergetool
for any merge conflict? This should apply for all merges, using merge
, rebase
, pull
, etc.
解决方案
You cannot (yet) make git do this.
This may or may not be an acceptable workaround.
Create a function in your ~/.bashrc
:
git()
{
if [[ $1 == "merge" ]] || [[ $1 == "rebase" ]] || [[ $1 == "pull" ]]; then
command git "$@"
rc=$?
if [[ $rc == 1 ]]; then
echo "There are conflicts, better run git-mergetool!!!"
# There might be some other condition that returns a '1',
# if so you can add another check like this:
# if grep Conflicts $(git --git-dir)/MERGE_MSG;
command git mergetool
fi
else
command git "$@"
fi
}
Mergetool isn't invoked when it merges:
$ git merge non_conflicting_branch
Merge made by the 'recursive' strategy.
bar | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bar
Mergetool is called when there are conflicts:
$ git merge conflicting_branch
Auto-merging foo
CONFLICT (content): Merge conflict in foo
Automatic merge failed; fix conflicts and then commit the result.
There are Conflicts, better run git-mergetool!!!
Mergetool is not called on other errors:
$ git merge adasds
fatal: adasds - not something we can merge
这篇关于如果出现合并冲突,如何让git自动打开mergetool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文