确定两个Git分支是否分开 [英] Determine whether two Git branches have diverged
问题描述
我想确定两个Git分支是否分开,或者其中一个分支可以简单地快速转发到另一个分支。
I'd like to determine whether two Git branches have diverged or whether one of the branches could simply be fast forwarded to the other branch.
我想检查其中一个分支的当前HEAD是否已在某个时刻合并到另一个分支中,或者它是否包含不在另一个分支中的提交。
In other words, I want to check whether the current HEAD of one of the branches has been merged into the other branch at some point or if it contains commits that are not in the other branch.
是否有一种方法可以在不实际合并两个分支的情况下进行?在这种情况下,简单的 git diff
没有帮助。
Is there a way to do this without actually merging the two branches? A simple git diff
does not help in this case.
推荐答案
I为此,我正在使用以下shell脚本代码段:
I'm using this shell script snippet for that purpose:
git_is_merged () {
local revlist
if revlist=$(git rev-list -1 "$1" --not "$2"); then
if [ "$revlist" = "" ]; then
echo "'$1' IS merged into '$2'."
else
echo "'$1' is NOT merged into '$2'."
fi
fi
}
alias gim='git_is_merged'
像 gim origin / devel origin / master
一样使用它来确定 origin / devel
合并到来源/母版
。
Use it like gim origin/devel origin/master
to determine whether origin/devel
is merged into origin/master
.
编辑:出于完整性考虑,如果仅使用命名分支,还可以使用
For the sake of completeness, if you are working with named branches only, you could also use
git branch --contains origin/devel | grep -q origin/master && echo "Merged" || echo "Not merged"
或
git branch --merged origin/master | grep -q origin/devel && echo "Merged" || echo "Not merged"
出于相同的目的。
这篇关于确定两个Git分支是否分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!