【问题标题】:User Access Control in gitgit中的用户访问控制
【发布时间】:2018-10-08 12:34:08
【问题描述】:

我有一个简单的问题。我们使用 Bitbucket 作为 git 提供者。 假设我是一个开发团队的经理。

我希望自己是唯一可以将代码合并到 master 分支的人。
其他团队成员可以签出 master 分支并创建新分支,但他们不能将代码合并到 master 分支。如何在 Git 中做到这一点?

【问题讨论】:

  • 各种 git 提供者,如 GitHub、Bitbucket、Gitlab,将具有满足您描述的要求的功能。您目前使用的是哪个提供商?
  • 最简单的方法是让你的 repo 对除你自己以外的任何用户都是只读的。这样一来,当他们的克隆中有内容时,您可以从开发人员那里提取内容,但他们永远无法将更改推送到您的存储库。
  • 你好junkangli,我们正在使用Bitbucket。

标签: git


【解决方案1】:

根据我的经验,最好的方法是只允许团队分叉存储库,而不是在读取功能时提交拉取请求(Github)或合并请求(Bitbucket)。

【讨论】:

    【解决方案2】:

    您的要求很容易实现,但这取决于您的工作方式。

    如果您使用的是 git 服务器,您可以“保护” 所需的分支不被合并。


    保护github下的分支


    保护分支以区分 bitbucket

    在这里您必须选择阻止所有更改并将您自己作为允许的用户


    Git 挂钩

    你可以通过一个简单的 pre-receive hook 来实现它,这又取决于你的 git 服务器

    例如:

    #!/bin/sh
    
    # Extract the desired information from the log message
    # You can also use the information passed out by the central repo if its available
    
    # %ae = Extract the user email from the last commit (author email)
    USER_EMAIL=$(git log -1 --format=format:%ae HEAD)
    
    # %an = Extract the username from the last commit (author name)
    USER_NAME=$(git log -1 --format=format:%an HEAD)
    
    # or use those values if you have them:
    # $USER, $GIT_AUTHOR_NAME, $GIT_AUTHOR_EMAIL
    
    if [ "$1" != refs/heads/master ] && [ CHECK_FOR_USER_NAME_OR_EMAIL ] {
        echo "ERROR:  you are not allowed to update master" >&2
        exit 1
    }
    

    【讨论】:

    • 看到您已经在选项列表中涵盖了钩子,我会从最初的评论中退缩一点;但不完全。大多数人似乎并不认为钩子“简单”,并且没有一个通用的“git 服务器”解决方案。 GitHub 不是 git; bitbucket 不是 git; gitlab 不是 git;并且围绕这一点有足够的混乱,我认为它应该比你提出的更清楚。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    相关资源
    最近更新 更多