我希望能够设置我们的分支,使得合并只能从开发分支到主分支。
我知道这听起来可能有些严苛,我应该问问自己,是否不信任团队中的开发人员…… 目前我还是不信任他们,因为他们刚开始熟悉Git。随着时间的推移,我会取消这个限制,但在此之前,这将是很有用的。这种设置可行吗?
谢谢, Mark。
我希望能够设置我们的分支,使得合并只能从开发分支到主分支。
我知道这听起来可能有些严苛,我应该问问自己,是否不信任团队中的开发人员…… 目前我还是不信任他们,因为他们刚开始熟悉Git。随着时间的推移,我会取消这个限制,但在此之前,这将是很有用的。这种设置可行吗?
谢谢, Mark。
merges_from
函数,并注意其上方的注释。由于链接在StackOverflow中有些棘手,因此我也会在此处包含实际函数。(请注意,此代码旨在与古老版本的Git一起使用,因此不使用像git for-each-ref --merged
这样的现代功能。)
# $1 is a merge commit. Find all its parents, except the first
# (which is "on" the branch being merged-into and hence not relevant).
# For each remaining parent, find which branch(es) contain them.
# If those branch heads *are* them, consider that the "source" of the merge.
#
# Note that this means if branches A and B both name commit 1234567,
# and you merge commit 1234567 into branch master, this considers
# the merge (with its one parent) to merge both branches A and B.
# That may not be ideal, but it is what we get...
merges_from()
{
local branches b src
set -- $($GIT rev-list --parents --no-walk $1)
shift 2
for i do
# git branch --contains may print something like
# * (no branch)
# or
# * (detached from blah)
# if HEAD is detached. This should not happen in
# a bare repo, but if it does, we'll add HEAD to
# our list.
branches=$($GIT branch --merged $i |
sed -e 's/\* (.*)/HEAD/' -e 's/^[* ]//')
set -- $branches
src=""
for b do
if [ $($GIT rev-parse $b) = $i ]; then
src="${src}${src:+ }$b"
fi
[ "$src" == "" ] && src="-"
done
echo $src
done
}