git - 在子模块中添加一个 git 子模块(嵌套子模块)

标签 git git-submodules

As described in this Question

是否有可能一个 git 子模块由多个其他 git 子模块组成,并且 super git repo 可以获取每个子模块的内容?

作者假设了一个像这样的 git 子模块层次结构:

  • repo 1
    • 子模块 xyz1
    • 子模块xyz2
  • repo 协议(protocol)2
    • 子模块 repo1

这个问题是关于在子模块中嵌套子模块的可能性:

  • repo 1
    • 子模块a
      • 子模块ab
      • 子模块ac

.gitmodules 的真实例子应该是这样的:

[submodule "Source/V8"]
    path = Source/V8
    url = https://chromium.googlesource.com/v8/v8.git
[submodule "Source/V8/build/gyp"]
    path = Source/V8/build/gyp
    url =  https://chromium.googlesource.com/external/gyp
[submodule "Source/V8/third_party/cygwin"]
    path = Source/V8/third_party/cygwin
    url = https://chromium.googlesource.com/chromium/deps/cygwin
[submodule "Source/V8/third_party/python_26"]
    path = Source/V8/third_party/python_26
    url = https://chromium.googlesource.com/chromium/deps/python_26
[submodule "Source/V8/third_party/icu"]
    path = Source/V8/third_party/icu
    url = https://chromium.googlesource.com/chromium/deps/icu52
[submodule "Source/V8/testing/gtest"]
    path = Source/V8/testing/gtest
    url = https://chromium.googlesource.com/chromium/testing/gtest
[submodule "Source/V8/testing/gmock"]
    path = Source/V8/testing/gmock
    url = https://chromium.googlesource.com/chromium/testing/gtest

注意子模块的路径是嵌套的:

  • 来源/V8
    • 源码/V8/build/gyp
    • 来源/V8/third_party/cygwin

我尝试了以下示例但没有成功:

 git submodule add https://chromium.googlesource.com/v8/v8.git   
 Source/V8
 git submodule add https://chromium.googlesource.com/external/gyp 
 Source/V8/build/gyp 

结果:

 The following path is ignored by one of your .gitignore files:
 Source/V8/build/gyp
 Use -f if you really want to add it.

使用 git submodule add -f 结果:

Cloning into 'Source/V8/build/gyp'...
remote: Sending approximately 10.28 MiB ...
remote: Total 16486 (delta 10444), reused 16486 (delta 10444)
Receiving objects: 100% (16486/16486), 10.28 MiB | 2.07 MiB/s, done.
Resolving deltas: 100% (10452/10452), done.
Checking connectivity... done.
fatal: Pathspec 'Source/V8/build/gyp' is in submodule 'Source/V8'
Failed to add submodule 'Source/V8/build/gyp'

如果可以实现这种情况,请现在告诉我。

更新:注意这个问题是关于创建子模块结构,而不是初始化它。

最佳答案

简短回答:是的。 归根结底,子模块是一个模块,但在另一个模块内。

这意味着如果您设置一个带有子模块的父仓库。您可以进入该子模块并在其中设置另一个模块。 这样,父存储库将看到您的子模块内部有一些更改,但不会看到其中有另一个子模块。

关于git - 在子模块中添加一个 git 子模块(嵌套子模块),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28110097/

相关文章:

c# - 是否可以从 CakeBuild 创建和 checkout 新的 git 分支?

Git lfs(大文件存储)说 lfs 管理的文件在 git lfs pull 之后被修改

Git找到第一个非本地提交

git - 包管理器与 Git 子模块/子树

git - 单个文件作为 Git 子模块

java - QueryDsl 不会为 git 子模块的 @Entity 类生成 q 类

git - 如何将 git 中的子模块更新为该外部仓库中的 HEAD 提交

git - 无法将git克隆到Kubernetes gitRepo卷中

git - 如何修复 git 中损坏的子模块配置?

ruby-on-rails - 是否有一个 gem 可以让 Git 和 Rails 协同工作以实现更强大的迁移?