Git 存储库中的 Git 存储库
我有一个主 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
远程存储库中也必须知道这一点,仅本地副本对我没有帮助,因为其他人检查了这一点并且必须能够编译所有内容。
I have a main git repository A and we are using sources out of another git repository B in a subdirectory of our main project.
Now it would be good to have the B repository checked out within the A repository in this used subdirectory.
If someone else then clones the repository of course he should get our main repository A and within that automatically the B repository.
Let me visualize the directory structure:
+ 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
This must be also known in the remote repository, just a local copy doesn't help me, because other people check this out and must be able to compile all the stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要阅读Git 子模块。
You'll want to read about Git submodules.
在 git 版本 1.7.11 及更高版本中使用 git subtree。
git subtree
优越到 git submodule 因为:支持(甚至在 v1.5.2 之前)
git subtree
不需要存储库的用户学习任何新内容,他们可以忽略事实上,您使用子树来管理依赖项git subtree
不会像git submodule
那样添加新的元数据文件(例如.gitmodule
)此外,如果您需要将现有存储库的子树分离到新存储库,
git subtree split< /code> 可以帮助你。
2020 年 2 月更新: 现在我更喜欢 subrepo 。
Use
git subtree
in git version 1.7.11 and above.git subtree
is superior to git submodule because:supported (even before v1.5.2)
git subtree
does not require users of your repository to learn anything new, they can ignore the fact that you are using subtree to manage dependenciesgit subtree
does not add new metadata files likegit submodule
does (such as.gitmodule
)Additionally, if you need to detach a subtree of your existing repository into a new repository,
git subtree split
can help you with that.UPDATE February 2020: Nowadays I like subrepo even more.
您可以在不使用子模块的情况下嵌套两个 git 存储库。假设ChildRepo是ParentRepo的子目录,并且都是git存储库。
如果您将文件添加到 ChildRepo,ParentRepo 将忽略它。当您提交它时,它将被添加到 ChildRepo 中。无法将 ChildRepo 中的文件添加到 ParentRepo。
更多信息:嵌套 GIT 存储库陷阱!
You can nest two git repo's without using submodules. Suppose ChildRepo is a subdirectory of ParentRepo, and both are git repositories.
If you add a file to ChildRepo, ParentRepo will ignore it. When you commit it it will be added to ChildRepo. It is not possible to add files within ChildRepo to ParentRepo.
More info: Nested GIT repo gotchas!