首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何避免ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm“的”合并分支“

如何避免ssh://gdcm.git.sourceforge.net/gitroot/gdcm/gdcm“的”合并分支“
EN

Stack Overflow用户
提问于 2011-03-30 06:50:08
回答 1查看 3K关注 0票数 0

在我们的项目中,一些贡献者喜欢直接工作,但仍然忘记了git pull --rebase

是否有一种方法可以在服务器端拒绝像Merge branch 'master' of ... into master这样的提交?

EN

回答 1

Stack Overflow用户

发布于 2011-03-30 09:00:04

作为VonC注释,您可以使用我为这个问题编写的pre-receive钩子的一个更简单的版本来完成这个任务。

要重新表述您所要求的内容,您需要在服务器上设置一个pre-receive钩子,该钩子将拒绝对具有任何非线性历史记录的主服务器进行任何推送,即引入与多个父服务器的任何提交。这个钩子应该做你想做的事:

代码语言:javascript
复制
#!/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:在中,对于链接问题,他演示了使用git rev-list --merges要整洁得多,所以我更新了这个脚本来使用它,并将它修复为遍历push试图更新的每个引用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5482887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档