如何配置现有的 git repo 由 UNIX 组共享

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3242282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:44:54  来源:igfitidea点击:

How to configure an existing git repo to be shared by a UNIX group

gitpermissionsshareshared

提问by Pistos

I have an existing git repo (a bare one) which has up to this point only been writable by me. I want to open it up to some UNIX user group, foo, so that all members of foo can push to it. I'm aware that I can easily set up a newgit repo with:

我有一个现有的 git repo(一个裸的),到目前为止只有我可以写。我想向某个 UNIX 用户组 foo 开放它,以便 foo 的所有成员都可以推送到它。我知道我可以轻松地设置一个新的git repo:

git init --bare --shared=group repodir
chgrp -R foo repodir

But I need the equivalent operation for an existingrepo dir.

但是我需要对现有repo 目录进行等效操作。

回答by David Underhill

Try this to make an existing repository in repodirwork for users in group foo:

试试这个,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")

回答by kixorz

In the repo dir execute following commands:

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

git config core.sharedRepository group
chgrp -R foo repodir
chmod -R g+w repodir

Edit: To address frequent confusion, groupis an actual keyword, you're not supposed to replace this with the name of the group.

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

回答by Andrea

Merging @David Underhilland @kixorzanswers, I made my own (definitive) solution.

合并@David Underhill@kixorz 的答案,我制定了自己的(最终)解决方案。

It is for barerepos and non-barerepos. There are only little differences between them, but in this way is clearer.

它适用于回购和非裸回购。它们之间只有很小的区别,但这样更清晰。

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

where:

在哪里:

  • <repo.git>is the bare repository directory, typically on the server (e.g. my_project.git/).
  • <group-name>is the group name for git users (e.g. users).
  • <repo.git>是裸存储库目录,通常在服务器上(例如my_project.git/)。
  • <group-name>是 git 用户的组名(例如users)。


NON-BARE REPOSITORY

非裸存储库

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

where:

在哪里:

  • <project_dir>is the project directory containing the .gitfolder.
  • <group-name>is the group name for git users (e.g. users).
  • <project_dir>是包含.git文件夹的项目目录。
  • <group-name>是 git 用户的组名(例如users)。

回答by nerfologist

This is probably not necessary, but it's worth pointing out that git init --bare --sharedalso sets the denyNonFastForwardsoption.

这可能不是必需的,但值得指出的是,git init --bare --shared它还设置了denyNonFastForwards选项。

git config receive.denyNonFastForwards true

The meaning of this option is as follows:

该选项的含义如下:

receive.denyNonFastForwards

If you rebase commits that you've already pushed and then try to push again, or otherwise try to push a commit to a remote branch that doesn't contain the commit that the remote branch currently points to, you'll be denied. This is generally good policy; but in the case of the rebase, you may determine that you know what you're doing and can force-update the remote branch with a -f flag to your push command.

receive.denyNonFastForwards

如果您对已经推送的提交进行变基,然后尝试再次推送,或者尝试将提交推送到不包含远程分支当前指向的提交的远程分支,您将被拒绝。这通常是好的政策;但是在 rebase 的情况下,您可能会确定您知道自己在做什么,并且可以使用 -f 标志强制更新远程分支到您的推送命令。

(from http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration)

(来自http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

回答by sarvagya kumar

In addition to the above answers of allowing a group to read/write you also need to add the user to the group (say "foo").

除了上述允许组读/写的答案外,您还需要将用户添加到组中(比如“foo”)。

sudo usermod -a -G [groupname] [username]

Note: you will have to first create user if it doesn't exist

注意:如果用户不存在,您必须先创建用户