如何配置要由UNIX组共享的现有git仓库

Pis*_*tos 88 git permissions share shared

我有一个现有的git repo(一个裸机),到目前为止只能由我写.我想打开一些UNIX用户组foo,这样foo的所有成员都可以推送它.我知道我可以轻松地设置一个新的 git repo:

git init --bare --shared=group repodir
chgrp -R foo repodir
Run Code Online (Sandbox Code Playgroud)

但我需要现有 repo目录的等效操作.

Dav*_*ill 104

尝试此操作以使repodir组中的用户可以使用现有存储库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")
Run Code Online (Sandbox Code Playgroud)

  • 我想补充一点,你可能还应该在repo的配置中设置config.sharedRepository = true.http://www.kernel.org/pub/software/scm/git/docs/git-config.html (13认同)
  • 您可以在现有仓库上使用`git init --shared`命令来设置配置值.您还需要执行`chmod`命令才能正确获取文件的权限. (4认同)
  • 这与我自己所做的非常接近,但我想得到一些外部确认。谢谢。:) 我也希望会有一个 git clone --shared=group 之类的东西,但克隆的 --shared 选项做了完全不同的事情。 (2认同)
  • 用户的 umask 似乎仍然适用于新创建的文件。这是你所期望的吗?我认为`core.sharedRepository` 的文档会提到这一点——如果用户没有将他们的所有文件组设为可写,这似乎毫无用处。 (2认同)

kix*_*orz 44

在repo目录中执行以下命令:

git config core.sharedRepository group
chgrp -R foo repodir
chmod -R g+w repodir
Run Code Online (Sandbox Code Playgroud)

编辑:为了解决经常混淆,group是一个实际的关键字,你不应该用组的名称替换它.

  • 其中`group`不是组的名称:) (24认同)
  • 对象和包文件应该是不可变的; 他们应该有权限444/r - r - r--. (7认同)
  • 在尝试`git config core.sharedRepository dev`然后键入`git config`后,我得到'致命:'git version``1.7.0.4`中的.git/config`中的'core.sharedrepository'的错误配置值(可能是版本)后) (3认同)
  • `git config core.sharedRepository group``group`不是组的名称,而是实际值! (3认同)

And*_*rea 39

合并@David Underhill@kixorz的答案,我制定了自己的(明确的)解决方案.

这是裸露的回购和非裸回购.它们之间只有很小的差异,但这种方式更清晰.

BARE REPOSITORY

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
Run Code Online (Sandbox Code Playgroud)

哪里:

  • <repo.git>是裸存储库目录,通常在服务器上(例如my_project.git/).
  • <group-name>是git用户的组名(例如用户).

非抢劫储藏室

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
Run Code Online (Sandbox Code Playgroud)

哪里:

  • <project_dir>是包含该.git文件夹的项目目录.
  • <group-name>是git用户的组名(例如用户).

  • 你可以通过运行 `chmod g=u` 来省去 `chmod g+w -R` 和 `chmod g+w .git/objects/pack/*` 的麻烦,它将用户的权限应用到组的权限上——它们可能是可写与否。如果 repo 包含只读文件或者 Git 有一天会创建其他只读文件,这更合适。 (3认同)