在我们的项目中,一些贡献者喜欢直接工作,但仍然忘记了git pull --rebase。
是否有一种方法可以在服务器端拒绝像Merge branch 'master' of ... into master这样的提交?
发布于 2011-03-30 09:00:04
作为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}`
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
endUpdate:在中,对于链接问题,他演示了使用git rev-list --merges要整洁得多,所以我更新了这个脚本来使用它,并将它修复为遍历push试图更新的每个引用。
https://stackoverflow.com/questions/5482887
复制相似问题