我希望能够设置我们的分支,以便合并只能从开发分支进入master。
我明白这也许听起来很严苛,我应该问问自己这个问题,我不相信团队中的开发人员......暂时我不会因为他们只是变得熟悉与Git。我及时删除限制,但在此之前这将是有用的。可能吗?
谢谢, 标记
答案 0 :(得分:5)
作为kowsky answered,可以在服务器端预接收挂钩中执行此操作。但令人惊讶的是,主要是因为Git的分支概念有点滑。
我写了一个pre-receive hook,除此之外还做了这个; the code is available here。请参阅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
}
答案 1 :(得分:0)