我有一个现有的 git repo(一个空的),到目前为止只有我可以写。我想向某个 UNIX 用户组 foo 开放它,以便 foo 的所有成员都可以推送到它。我知道我可以通过以下方式轻松设置新的git 存储库:
git init --bare --shared=group repodir
chgrp -R foo repodir
但是我需要对现有的repo 目录进行等效的操作。
我有一个现有的 git repo(一个空的),到目前为止只有我可以写。我想向某个 UNIX 用户组 foo 开放它,以便 foo 的所有成员都可以推送到它。我知道我可以通过以下方式轻松设置新的git 存储库:
git init --bare --shared=group repodir
chgrp -R foo repodir
但是我需要对现有的repo 目录进行等效的操作。
尝试这样做以使现有存储库repodir
为 group 中的用户工作foo
:
chgrp -R foo repodir # set the group
chmod -R g+rw repodir # allow the group to read/write
chmod g+s `find repodir -type d` # new files get group id of directory
git init --bare --shared=all repodir # sets some important variables in repodir/config ("core.sharedRepository=2" and "receive.denyNonFastforwards=true")
合并@David Underhill和@kixorz 的答案,我制定了自己的(确定的)解决方案。
它适用于裸回购和非裸回购。它们之间只有很小的区别,但这样更清楚。
裸存储库
cd <repo.git>/ # Enter inside the git repo
git config core.sharedRepository group # Update the git's config
chgrp -R <group-name> . # Change files and directories' group
chmod -R g+w . # Change permissions
chmod g-w objects/pack/* # Git pack files should be immutable
find -type d -exec chmod g+s {} + # New files get directory's group id
在哪里:
<repo.git>
是裸存储库目录,通常在服务器上(例如my_project.git/
)。<group-name>
是 git 用户的组名(例如users)。非裸存储库
cd <project_dir>/ # Enter inside the project directory
git config core.sharedRepository group # Update the git's config
chgrp -R <group-name> . # Change files and directories' group
chmod -R g+w . # Change permissions
chmod g-w .git/objects/pack/* # Git pack files should be immutable
find -type d -exec chmod g+s {} + # New files get directory's group id
在哪里:
<project_dir>
是包含文件夹的项目目录.git
。<group-name>
是 git 用户的组名(例如users)。在 repo 目录中执行以下命令:
git config core.sharedRepository group
chgrp -R foo repodir
chmod -R g+w repodir
编辑:为了解决频繁的混淆,group
是一个实际的关键字,你不应该用组的名称替换它。
这可能不是必需的,但值得指出的是,git init --bare --shared
它还设置了denyNonFastForwards选项。
git config receive.denyNonFastForwards true
该选项的含义如下:
receive.denyNonFastForwards
如果您对已经推送的提交进行变基,然后再次尝试推送,或者尝试将提交推送到不包含远程分支当前指向的提交的远程分支,您将被拒绝。这通常是好的政策;但是在变基的情况下,您可以确定您知道自己在做什么,并且可以使用 -f 标志强制更新远程分支到您的推送命令。
(来自http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration)
除了上述允许组读/写的答案之外,您还需要将用户添加到组中(比如“foo”)。
sudo usermod -a -G [groupname] [username]
注意:如果用户不存在,则必须先创建用户