如何避免ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm的合并分支'master' [英] How to avoid "Merge branch 'master' of ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm"
问题描述
我们项目中的一些贡献者喜欢直接在master上工作,但仍然忘记了 git pull --rebase
。
有没有办法拒绝服务器端提交像合并分支'主'...到主
?
作为 VonC 的评论,您可以使用简单版本的 pre-receive
钩子,我为这个问题编写的。
重新解释你问的问题,你会想要一个服务器上的 pre-receive
钩子,它会拒绝任何推送给有非线性历史记录的主服务器,即引入任何提交多个父进程。这个钩子应该做你想做的:
#!/ usr / bin / ruby -w
ref_to_check =refs / heads / master
STDIN.each_line do | line |
rev_old,rev_new,ref = line.split()
if ref == ref_to_check
merges_introduced =`git rev-list --merges#{rev_old} .. #{rev_new}`
除非merges_introduced.strip.empty?
STDERR.puts拒绝推送到#{ref},因为它会通过引入以下合并提交来创建非线性的
STDERR.puts历史记录:
STDERR.puts merges_introduced
出口(1)
结束
结束
结束
更新:在 git rev-list --merges 非常简洁,所以我已经更新了这个脚本来使用它,并且修正它以循环推送尝试更新的每个ref。
Some contributors in our project likes to work on master directly and still forget to git pull --rebase
.
Is there a way to refuse on the server side commit with commit like Merge branch 'master' of ... into master
?
As VonC comments, you can do this with a simpler version of the pre-receive
hook that I wrote for that question.
To rephrase what you're asking, you would like a pre-receive
hook on your server that will refuse any push to master which has any non-linear history, i.e. introduces any commit with more than one parent. This hook should do what you want:
#!/usr/bin/ruby -w
ref_to_check = "refs/heads/master"
STDIN.each_line do |line|
rev_old, rev_new, ref = line.split(" ")
if ref == ref_to_check
merges_introduced = `git rev-list --merges #{rev_old}..#{rev_new}`
unless merges_introduced.strip.empty?
STDERR.puts "Refusing push to #{ref}, since it would create non-linear"
STDERR.puts "history by introducing the following merge commits:"
STDERR.puts merges_introduced
exit(1)
end
end
end
Update: in Jefromi's answer to the linked question, he demonstrates that using git rev-list --merges
is much neater, so I've updated this script to use that, and fixed it to loop over every ref that the push is trying to update.
这篇关于如何避免ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm的合并分支'master'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!