对Monorepo中目录的细粒度访问 [英] Granular access to directories within monorepo

查看:110
本文介绍了对Monorepo中目录的细粒度访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读monorepos的优点,但尚未发现共享存储库的一部分



假设组织有一个用于客户/服务器Web应用程序的存储库。他们雇用承包商来设计客户的某些部分。他们如何让承包商仅访问相关的客户代码?甚至稀疏

考虑使用 git子树



有了 git子树,您将能够:




  • 创建一个由子树组成的monorepo,每个子树都可以链接到单独的远程存储库。



    给定您的示例用例,承包商将只能访问绑定到monorepo的单个子树的远程仓库。


  • 有一个单一的汇总/统一历史记录(monorepo的点)


  • 从子树远程更改为monorepo


  • 将在monorepo的任何子树中进行的更改推送到其单独的远程


  • 保持简单/轻松的工作流。


    git子树不需要重新访问您存储库的用户以学习新知识。他们可以忽略您正在使用 git子树来管理依赖项的事实。





有关优点/缺点列表,请查看Atlassian的 Git子树:Git子模块的替代方案。。尽管我认为本文中的示例步骤相当局限,甚至还不算过时。



要进行逐步演示,并在每个步骤中提供 git log 详细信息




  • 与Atlassian文章相比,使用 git子树 将多个存储库合并成一个monorepo,同时保留历史记录,比Atlassian文章更干净,更合乎逻辑。

  • git子树:教程还包括逐步操作和结果,以在monorepo中进行更改并推送到子树repo,反之亦然,并给出了一些不错的技巧。它确实提到了一个警告,那就是包含子树拉取的重设基础不起作用。


    不要试图以此为基础。按原样推。如果您重新设置基础,则在执行下一个子树提取操作时,git子树将无法协调提交。


    作为基础,我在下面链接的Atlassian后续文章提供了一种解决方法。


  • 我通常不喜欢看视频,但是 Git子树简介一个值得一看的地方,并且有很多细节。此外,它比其他所有文章都更新(2019)。



如果您想获得一个潜在的了解,

strong>:





monorepo-operator 可能的工具>使基于子树的monorepo的管理更加轻松。我还没有使用过它,也无法担保它,但也许值得一试。


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:

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.

解决方案

Consider using git subtree.

With git subtree you will be able to:

  • create a monorepo composed of subtrees, each of which can be linked to separate remote repos.

    Given your example use case, the contractor would be given access to only the remote repo tied to a single subtree of the monorepo.

  • have a single aggregate/unified history (the point of a monorepo)

  • pull changes from subtree remotes into the monorepo

  • push changes made in any subtree of the monorepo to its separate remote

  • keep your simple/easy workfows.

    git subtree does not require users of your repository to learn anything new. They can ignore the fact that you are using git subtree to manage dependencies."

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.

For step by step demonstrations with git log details at each step:

  • 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,

    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.

    If you must do a rebase, the follow up Atlassian article I link below provides a workaround.

  • I usually hate watching videos but Introduction to Git Subtrees  one looks worth it and has lots of detail. Also it is far more recent (2019) than all the other articles. It's comforting to see in advance what you'll be dealing with.

If you want an under the covers understanding:

  • 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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆