如何编写一个 git hook 来限制写入分支? [英] How to write a git hook to restrict writing to branch?

查看:42
本文介绍了如何编写一个 git hook 来限制写入分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 master 分支的写访问权限限制为只有几个开发人员,同时允许其他人拉取所有内容并推送到其他非 master 分支.想法是,开发人员将推送到其他某个分支,然后如果代码通过审查,审查者会将其合并到主分支.

I'd like to restrict write access for the master branch to only several developers, while allowing others to pull everything and push to other non-master branches. Idea is that a developer would push to some other branch and then if code passes review, reviewer would merge it into the master branch.

我很确定这可以通过 git commit hook 轻松完成,但我不知道 python,这似乎是一个通用问题,肯定有人已经写过了.你知道我在哪里可以找到这样的脚本吗?或者如果你身边有一个,请粘贴在这里,对于像我这样的懒人.

I'm pretty sure that this can be easily done with a git commit hook, but I don't know python and this seems like such a generic problem, that somebody must have written it already. Do you know where I could find such a script? Or if you have one lying around, please paste it here, for lazy people like me.

推荐答案

我认为可以使用这样的脚本,但它不是权限管理的正确位置,而应该在 git 服务器端完成.例如,在 gitosis 中,您可以在 gitosis-admin 存储库中的文件 gitosis.conf 中进行此配置.

I think it could be possible to use such script but it is not the right place for rights management, it should be rather done on git server side. For example in gitosis you do this configuration in gitosis-admin repository in file gitosis.conf.

钩子管理的安全性很容易被破坏,只有服务器可以跟踪这些事情,请查看您服务器的文档以了解如何限制访问的详细信息.

Security managed by a hook can be easily broken, only server can keep track of this things, please check documentation of your server for details how to restrict access.

这篇关于如何编写一个 git hook 来限制写入分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆