Mat*_*hen 25 git merge mergetool
如何让git自动运行git mergetool
任何合并冲突?这应该适用于所有的合并,使用merge
,rebase
,pull
,等.
你不能(还)让git这样做.
这可能是也可能不是可接受的解决方法.
在你的~/.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
}
Run Code Online (Sandbox Code Playgroud)
合并时不会调用Mergetool:
$ git merge non_conflicting_branch
Merge made by the 'recursive' strategy.
bar | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bar
Run Code Online (Sandbox Code Playgroud)
当存在冲突时调用Mergetool:
$ 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!!!
Run Code Online (Sandbox Code Playgroud)
没有在其他错误上调用Mergetool:
$ git merge adasds
fatal: adasds - not something we can merge
Run Code Online (Sandbox Code Playgroud)
您始终可以使用别名
\n\nalias \'git-merge\'=\'git merge && git mergetool\'\nalias \'git-rebase\'=\'git rebase && git mergetool\'\nalias \'git-pull\'=\'git pull && git mergetool\'\n
Run Code Online (Sandbox Code Playgroud)\n\n和/或按照这些思路编写帮助程序脚本
\n\n#/bin/bash\ngit $*\n[ "$(git ls-files \xe2\x80\x93abbrev \xe2\x80\x93unmerged | wc -l)" -gt 0 ] && git mergetool\n
Run Code Online (Sandbox Code Playgroud)\n\n进而
\n\nalias git=\'~/.git/git-script\'\n
Run Code Online (Sandbox Code Playgroud)\n\n没有直接调用 mergetool 的方法,因为它只是几种合并方法之一(请参阅 man 1 git-merge 中的“如何解决冲突”)。
\n