对 monorepo 中目录的精细访问 [英] Granular access to directories within monorepo
问题描述
我一直在阅读关于 monorepos 的优势,但还没有找到解决 共享部分存储库:
I've been reading about the advantages of monorepos, but haven't yet found a mitigation for the problem of sharing parts of a repo:
假设一个组织有一个用于客户端/服务器 Web 应用程序的 monorepo.他们聘请承包商来设计客户的某些部分.他们如何让承包商只能访问相关的客户代码?甚至 稀疏结帐并非微不足道.
Let's say an organization has a monorepo for a client/server web application. They hire a contractor to work on the design of some part of the client. How can they give the contractor access to only the relevant client code? Even sparse checkouts are not trivial.
推荐答案
考虑使用 git subtree
.
使用git subtree
,您将能够:
创建一个由子树组成的 monorepo,每个子树都可以链接到单独的远程仓库.
create a monorepo composed of subtrees, each of which can be linked to separate remote repos.
鉴于您的示例用例,承包商将只能访问与 monorepo 的单个子树相关联的远程存储库.
有一个单一的聚合/统一历史(monorepo 的点)
have a single aggregate/unified history (the point of a monorepo)
从子树远程拉取更改到 monorepo
pull changes from subtree remotes into the monorepo
将 monorepo 的任何子树中所做的更改推送到其单独的远程
push changes made in any subtree of the monorepo to its separate remote
保持简单/轻松的工作流程.
keep your simple/easy workfows.
git subtree
不需要存储库的用户学习任何新东西.他们可以忽略您使用 git subtree
来管理依赖项这一事实."
git subtree
does not require users of your repository to learn anything new. They can ignore the fact that you are usinggit subtree
to manage dependencies."
有关利弊列表,请查看 Atlassian 的 Git子树:Git 子模块的替代方案.尽管我认为本文中的示例步骤即使不是过时的也相当有限.
For a list of pros/cons check out Atlassian's Git subtree: the alternative to Git submodule. Though I think the example steps in this article are rather limited if not outdated.
关于每一步的git log
详细信息的分步演示:
For step by step demonstrations with git log
details at each step:
- 将多个存储库合并到一个monorepo中的示例和步骤,在保留历史记录的同时,使用
git subtree
比 Atlassian 文章更清晰、更合乎逻辑. git 子树:教程还包括步骤在 monorepo 中进行更改和推送到子树 repo 的逐步操作和结果,反之亦然,并提供了一些很好的提示.它确实提到了一个警告,那就是包含子树拉取的变基不起作用.另一篇文章解释说,
- The example and steps in Merging multiple repositories into a monorepo, while preserving history, using
git subtree
are cleaner and more logical than the Atlassian article. git subtrees: a tutorial also includes step by step actions and results for making changes in the monorepo and pushing to the subtree repo, and vice versa, and gives some good tips. It does mention one caveat, and that is rebases that include subtree pulls don't work. Another post explains,
不要试图重新设置它.按原样推它.如果你变基,当你执行下一个子树拉取时,git subtree 将无法协调提交.
Do not be tempted to rebase this. Push it as is. If you rebase, git subtree won’t be able to reconcile the commits when you do your next subtree pull.
如果您必须进行变基,我在下面链接的后续 Atlassian 文章提供了一种解决方法.
If you must do a rebase, the follow up Atlassian article I link below provides a workaround.
如果您想深入了解:
- 这个优秀的 SO 答案 解释了
git subtree
和 git 之间的区别子树合并策略 (git merge -s subtree
).本质上,前者在幕后使用后者.换句话说,git 的 瓷器 与 管道 的概念. - 关于 Git 子树合并的 GitHub 文章如果您喜欢这种方法,请使用合并策略.
- 以上 Atlassian 文章的后续内容在 git subtree 的幕后".
- 掌握 Git 子树 也不错,并提到了一些其他细节您可能会也可能不会认为可以接受,并且包含我提供的所有链接中最详细的分步操作和结果.
- 有关
git subtree
如何产生的历史、它的内部工作原理以及子树如何优于子模块,请参阅 Git:子模块与子树.
- This excellent SO answer explains the difference between
git subtree
and the git subtree merge strategy (git merge -s subtree
). In essence former uses the latter under the covers. In other words git's notion of porcelain vs plumbing. - GitHub article about Git subtree merges uses the merge strategy if you prefer that approach.
- A followup to the Atlassian article above gets more "Under the hood of git subtree".
- Mastering Git subtrees is also good and mentions a couple of other details that you may or may not find acceptable, and has the most detailed step-by-step actions and results of all the links I've provided.
- For some history on how
git subtree
came about, and how it works internally, as well as how subtrees are better than submodules, see Git: submodules vs. subtrees.
monorepo-operator 是一种工具,可以管理您的基于子树的 monorepo 更容易.我没有使用过它,也不能保证它,但可能值得一试.
monorepo-operator is a tool that may make managing your subtree-based monorepo easier. I haven't used it and cannot vouch for it, but might be worth checking out.
这篇关于对 monorepo 中目录的精细访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!