如何设置不同用户只能看到某些部分的 git 存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1196312/
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 06:48:10  来源:igfitidea点击:

How to set up a git repository where different users can only see certain parts?

securitygitversion-controlrepositoryaccess-control

提问by Joseph Garvin

How do you set up a git repository where some users can see certain parts of the source code and other users can see all of it? I've seen lots of guides for only giving certain users commit access, but these assume everyone should have read access. I've also heard of gitosis, but I'm not sure it supports this and it hasn't had any commits in over a year so I think it's dead.

你如何设置一个 git 存储库,让一些用户可以看到源代码的某些部分,而其他用户可以看到全部?我看过很多只给特定用户提交访问权限的指南,但这些都假设每个人都应该有读取权限。我也听说过 gitosis,但我不确定它是否支持这一点,并且它在一年多的时间里没有任何提交,所以我认为它已经死了。

回答by Jakub Nar?bski

In short: you can't. Git is snapshot based (at conceptual level at least) version control system, not changeset based one. It treats project (repository) as a whole. The history is a history of a project, not a union of single-file histories (it is more than joining of per-file histories).

简而言之:你不能。Git 是基于快照(至少在概念级别)的版本控制系统,而不是基于变更集的版本控制系统。它将项目(存储库)视为一个整体。历史是一个项目的历史,而不是单个文件历史的联合(它不仅仅是加入每个文件的历史)。

Using hooks like update-paranoidhook in contrib, or VREFsmechanism of gitolite, you can allow or forbid access to repository, you can allow or forbid access to individual branches. You can even forbid any commits that change things in specified subdirectory. But the project is always treated as a whole.

使用update-paranoidcontrib 中的 hook 或 的VREFs机制等挂钩gitolite,您可以允许或禁止访问存储库,您可以允许或禁止访问单个分支。您甚至可以禁止任何更改指定子目录中内容的提交。但项目始终被视为一个整体。

Well, there is one thing you can do: make a directory you want to restrict access to into submodule, and restrict access to this submodule repository.

好吧,您可以做一件事:将要限制访问的目录创建到submodule 中,并限制对该子模块存储库的访问。

回答by bdonlan

The native git protocol doesn't support this; git assumes in many places that everybody has a completecopy of allof the history.

原生 git 协议不支持这个;git 在很多地方都假设每个人都拥有所有历史记录的完整副本。

That said, one option may be to use git-subtreeto split off part of the repository into its own subset repository, and periodically merge back.

也就是说,一种选择可能是使用git-subtree将部分存储库拆分为自己的子集存储库,并定期合并回来。

回答by J?rg W Mittag

Git doesn't support access control on the repository. You canhowever, implement access control on the repository yourself, by using hooks, more specifically the updatehook.

Git 不支持对存储库的访问控制。但是,您可以通过使用钩子,更具体地说是钩子自己对存储库实施访问控制。update

回答by Cascabel

J?rg has already pointed out that you can use hooks to do this. Exactly which hook(s) you need depends on your setup. If you want the permissions on a repo that gets pushed to, you'll need the updatehook like he said. However, if it's on a repo that you're actually working in (committing and merging), you'll also need the pre-commitand post-mergehooks. The githooks manpage(J?rg linked to this too) notes that there's in fact a script in the contrib section demonstrating a way to do this. You can get this by grabbing a git tarball, or pull it out of git's gitweb repo: setgitperms.perl. Even if you're only using the update hook, that might be a useful model.

J?rg 已经指出你可以使用钩子来做到这一点。您究竟需要哪个挂钩取决于您的设置。如果您想要推送到的回购的权限,您将需要update像他所说的钩子。但是,如果它在您实际工作的存储库上(提交和合并),您还需要pre-commitandpost-merge钩子。该githooks手册页(J·RG链接到这个太)注意到,实际上是在contrib部分展示的方式来做到这一点的脚本。你可以通过抓取一个 git tarball 来获得它,或者把它从 git 的 gitweb 存储库中提取出来:setgitperms.perl。即使您只使用更新挂钩,这也可能是一个有用的模型。