是否可以将多个 git 个存储库保留在 "umbrella" 个存储库下?

Is it possible to keep several git repositories under "umbrella" one?

情况如下:

# Want this folder to be "umbrella" in order not to spawn 
# a lot of github repos later on (you can consider it 
# dotfiles-like repository with a lot of remotely pulled 
# projects where each should be occasionally updated 
# and "custom" patches applied) 
mytoolbox/
  .git/
  proj1/ 
    .git/
    ..
  proj2/
    .git/
    ..
  proj3/
    .git/
    ..
  file1
  file2
  ..

经过一番谷歌搜索后,我偶然发现了 git submodulesubtrees。第一个似乎只是继续跟踪最后一次提交和对远程的引用(.gitmodules 下没有实际内容的链接列表)。并且 - 经过几次尝试 - 如果它符合我的目的,我没有想到第二个。可能有人可以提出更好的解决方案。 坦率地说,前阵子我为此使用了 Dropbox :)

两部分答案:

  1. git 子树背后的想法是什么? git 子树的目的只是为了在您的 parent 存储库中拥有另一个存储库的完整副本。它基本上只是围绕 vanilla git 编写的一些脚本,因此您的其他用户将不必执行子模块命令来访问子树内容,但它实际上是相同的想法。

  2. 建议更好的解决方案?在我个人看来,与子模块相比,子树是更好的选择,因为它没有额外的命令,而且它提供的简单性,但它很容易给你带来麻烦,比如在变基时。

我目前正在使用 git subrepo,它与 subtree 的基本思想完全相同,但执行得更好,更周到,以避免一些缺点。我在变基时做了一些额外的脚本来修补指向 parents 的指针,所以它不是完全微不足道的,但它是我发现的 2018 年的最佳选择。