2010-12-21 250 views
29

我有一个主要的git存储库A,我们正在使用另一个git存储库B在我们的主项目的子目录中的源。 现在,在此使用的子目录中的A存储库中检出B存储库会很好。 如果其他人然后克隆存储库,当然他应该得到我们的主存储库A并且在那里自动存储B存储库。Git存储库内的Git存储库

让我想象的目录结构:

 
+ 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 

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

+4

你应该看看你的需求的Git子模块:http://book.git-scm.com/5_submodules.html – 2010-12-21 14:32:04

+1

更新后的链接:http://schacon.github.io/gitbook/5_submodules.html – twasbrillig 2014-11-14 05:20:59

+0

博客post解释了每种方法的优缺点[Git Submodule:Git Subtree](http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/)。 – 2016-02-16 13:34:23

回答

22

你会想要阅读约Git submodules

+1

或者从Pro Git书籍:http://progit.org/book/ch6-6.html – bdukes 2010-12-21 15:18:50

5

你可以在不使用子模块的情况下嵌套两个git仓库。假设ChildRepo是ParentRepo的子目录,并且都是git存储库。

+ ParentRepo 
    - ChildRepo 

如果您将文件添加到ChildRepo,ParentRepo将忽略它。当你提交它时,它会被添加到ChildRepo。无法在ChildRepo内向ParentRepo添加文件。

更多信息:Nested GIT repo gotchas!

5

使用git subtree在Git版本1.7.11及以上。 git subtree is superior to git submodule因为:

  • 管理简单的工作流程很简单。混蛋旧版本的 支持(甚至在V1.5.2)
  • 子项目的代码是超级项目的克隆完成
  • git subtree后并不需要你的资料库的用户学习任何新的可用的权利,他们可以忽略您正在使用的子树来管理依赖
  • 事实
  • git subtreegit submodule做(如 .gitmodule
  • 子树的内容可以修改不增加新的元数据文件,而无需的一个独立的存储设备拷贝依赖于其他地方

此外,如果您需要detach a subtree of your existing repository into a new repository,git subtree split可以帮助你。