Git 存储库中的 Git 存储库

发布于 2024-10-08 07:40:56 字数 457 浏览 0 评论 0原文

我有一个主 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悲欢浪云 2024-10-15 07:40:56

您需要阅读Git 子模块

You'll want to read about Git submodules.

要走干脆点 2024-10-15 07:40:56

在 git 版本 1.7.11 及更高版本中使用 git subtree。 git subtree 优越到 git submodule 因为:

  • 简单工作流程的管理很容易。旧版本的 git 是
    支持(甚至在 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:

  • Management of a simple workflow is easy. Older versions of git are
    supported (even before v1.5.2)
  • The sub-project’s code is available right after the clone of the super project is done
  • 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 dependencies
  • git subtree does not add new metadata files like git submodule does (such as
    .gitmodule)
  • Contents of the subtree can be modified without having a separate repository copy of the dependency somewhere else

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.

蹲在坟头点根烟 2024-10-15 07:40:56

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

+ ParentRepo
  - ChildRepo

如果您将文件添加到 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.

+ ParentRepo
  - ChildRepo

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文