Git存储库中的Git存储库

Buu*_*uuh 37 git directory clone repository subdirectory

我有一个主git存储库A,我们在主项目的子目录中使用另一个git存储库B中的源代码.现在最好在这个使用过的子目录中的A存储库中检出B存储库.如果其他人然后克隆了存储库,他当然应该获得我们的主存储库A并在其中自动获取B存储库.

让我可视化目录结构:

+ main_repository       - the root directory of the main Repository
  + src                 - directory containing the source 
    + foreignRepo       - this should be the root directory of another git repo
  + binaries
  + other

这必须在远程存储库中也是已知的,只是本地副本对我没有帮助,因为其他人检查这一点并且必须能够编译所有的东西.

Adr*_*scu 24

您将要阅读有关Git子模块的信息.


Joh*_*hee 7

git subtree在git 1.7.11及更高版本中使用. git subtree优于git子模块,因为:

  • 简单管理简单的工作流程.支持旧版本的git(甚至在v1.5.2之前)
  • 超级项目的克隆完成后,子项目的代码就可用了
  • git subtree 不要求您的存储库用户学习任何新东西,他们可以忽略您使用子树来管理依赖项的事实
  • git subtree不添加新的元数据文件git submodule(例如 .gitmodule)
  • 可以修改子树的内容,而无需在其他位置具有依赖项的单独存储库副本

此外,如果您需要将现有存储库的子树分离到新存储库中,git subtree split可以帮助您.


Sjo*_*erd 6

您可以在不使用子模块的情况下嵌套两个git repo.假设ChildRepo是ParentRepo的子目录,都是git存储库.

+ ParentRepo
  - ChildRepo
Run Code Online (Sandbox Code Playgroud)

如果将文件添加到ChildRepo,ParentRepo将忽略它.提交时,它将被添加到ChildRepo.无法将ChildRepo中的文件添加到ParentRepo.

更多信息:嵌套的GIT回购陷阱!

  • 您需要将“ChildRepo”放入“.gitignore”中吗? (2认同)