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
这必须在远程存储库中也是已知的,只是本地副本对我没有帮助,因为其他人检查这一点并且必须能够编译所有的东西.
git subtree
在git 1.7.11及更高版本中使用. git subtree
优于git子模块,因为:
git subtree
不要求您的存储库用户学习任何新东西,他们可以忽略您使用子树来管理依赖项的事实git subtree
不添加新的元数据文件git submodule
(例如
.gitmodule
)此外,如果您需要将现有存储库的子树分离到新存储库中,git subtree split
可以帮助您.
您可以在不使用子模块的情况下嵌套两个git repo.假设ChildRepo是ParentRepo的子目录,都是git存储库.
+ ParentRepo
- ChildRepo
Run Code Online (Sandbox Code Playgroud)
如果将文件添加到ChildRepo,ParentRepo将忽略它.提交时,它将被添加到ChildRepo.无法将ChildRepo中的文件添加到ParentRepo.
更多信息:嵌套的GIT回购陷阱!