如何在git仓库上正确使用组文件权限?

发布于 2024-10-14 23:26:40 字数 371 浏览 3 评论 0原文

我们通过文件路径访问共享 git 存储库,出于各种原因我现在将省略它,使用 --shared=group 创建。

我们有不同的 UNIX 组,但都共享一个公共组。如果我在 git 存储库上运行 chgrp -R,每个人都可以从中读取,但如果有人经常写入它,则会创建不使用公共组的新文件。

这个问题似乎是因为我们的主要组不是共享组,如果我们运行 newgrp,一切似乎都运行良好。

但这种方法也存在一些问题; newgrp 很慢并且会生成一个新的 shell,这让我认为在 .bash_profile 中调用它是一个坏主意,甚至没有考虑我们是否希望所有新文件都使用共同组。不过,在进行任何 git 工作之前依赖内存来运行它似乎也是一场灾难。

那么...有什么建议吗?

We're accessing a shared git repository via file paths, for various reasons I'll omit for now, created with --shared=group.

We have various unix groups but all share a common group. If I run a chgrp -R on the git repository everyone can read from it, but if someone writes to it more often than not new files are created which do not use the common group.

This problem appears to be because our primary group is not the shared one and if we run a newgrp all seems to work well.

There are issues with this approach though; newgrp is slow and it spawns a new shell, which makes me think calling it in a .bash_profile would be a bad idea, without even considering whether or not we'd want all our new files to use the common group. Relying on memory to run it before doing any git work seems like a recipe for disaster too though.

So... any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

如痴如狂 2024-10-21 23:26:40

尚未使用 --shared 创建的现有存储库可以使用以下命令共享:

# make the repository shared
git config core.sharedRepository group # or whatever other sharing option
# fix the setgid bit
find . -type d | xargs chmod g+s
# repair the permissions
chmod -R g+r *

An existing repository that has not been created with --shared can be turned shared using following commands:

# make the repository shared
git config core.sharedRepository group # or whatever other sharing option
# fix the setgid bit
find . -type d | xargs chmod g+s
# repair the permissions
chmod -R g+r *
静若繁花 2024-10-21 23:26:40

您还需要在组上设置 setgid 位

chgrp -R GROUP /path/to/repo
find /path/to/repo -type d -print0 | xargs -0 chmod g+s 

You need to set the setgid bit on the group as well.

chgrp -R GROUP /path/to/repo
find /path/to/repo -type d -print0 | xargs -0 chmod g+s 
幸福丶如此 2024-10-21 23:26:40

这是一个裸仓库吗?如果它是一个裸存储库并且您在创建它时使用了 --shared 那么这种情况不应该发生,这就是我问的原因。

如果它是一个裸仓库,可能某些目录已更改为 gs,如果发生这种情况,您只需要 chmod g+x 全部目录,确保不对任何文件执行此操作。比这更简单的方法可能是 git init --bare --shared=group 一个新的存储库,然后将内容从某人的克隆推回给它。

Is this a bare repo? If its a bare repo and you used --shared when you created it then this shouldn't be happening which is why I'm asking.

If it is a bare repo maybe some of the directories got changed to g-s, if that happened you need to either chmod g+x all the directories only, make sure you don't do it to any files. An easier way than that might be to just git init --bare --shared=group a new repo and push the content back to it from somebodies clone.

深府石板幽径 2024-10-21 23:26:40

一旦裸存储库具有 shared=group 标志,git 将处理其余的事情,因此以下操作只需执行一次。此外,setgid 已不再用于此用途。在这里,我复制/粘贴 我来自 serverfault 的答案

假设 repogroup 是您的组,并且您有cd 到 repo 目录:

首先将共享标志更改为 group

git config core.sharedRepository group 

注意:这里必须使用关键字 group,而不是组名称。
这相当于使用选项 --shared=group 创建裸存储库。

然后更改整个存储库的组:

chgrp -R repogroup .

要确保现有目录是组可写的 (g+w),
并且现有的可执行文件也成为组可执行文件(g+X
您还需要:

chmod -R g+wX .

完成此操作后,git 将尊重 shared=group 标志,并在下面处理现有文件和新文件的组权限,因此您将不再需要到umaskchgrp

如果我找到它,我会将来源放在评论中。

Once the bare repository has the shared=group flag, git will take care of the rest, so the following has to be done only once. Also setgid is deprecated for this use. Here I copy/paste my answer from serverfault:

Assuming repogroup is your group, and you have cd to the repo directory:

First change the shared flag to group:

git config core.sharedRepository group 

Note: here you must use the keyword group, not the group name.
This is equivalent to creating the bare repository with option --shared=group.

Then change the group for the whole repository:

chgrp -R repogroup .

To make sure that existing directories are group-writable (g+w),
and existing executables also become group-executables (g+X)
you also need to:

chmod -R g+wX .

Once you have done this, git will honor the shared=group flag and take care of group permissions in the following, both for existing and new files, so you'll never need again to umask or chgrp.

I'll put the source in a comment if I find it back.

ヤ经典坏疍 2024-10-21 23:26:40

我必须使用上述答案的组合:

git config core.sharedRepository group
chgrp -R GROUP /path/to/repo
find /path/to/repo -type d -exec chmod g+rwxs {} \;

I had to use a combination from the above answers:

git config core.sharedRepository group
chgrp -R GROUP /path/to/repo
find /path/to/repo -type d -exec chmod g+rwxs {} \;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文