一个 Git 子模块能够由多个其他 Git 子模块组成,而主 Git 仓库能够获取每个子模块的内容吗?
作者假定了这样的 Git 子模块层级结构:
- repo1
- submodule xyz1
- submodule xyz2
- repo2
- submodule repo1
这个问题是关于在子模块中嵌套子模块的可能性:
- repo1
- submodule a
- submodule ab
- submodule ac
- submodule a
一个 .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
请注意,子模块的路径是嵌套的:
- Source/V8
- Source/V8/build/gyp
- Source/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'
请告诉我是否有可能实现这个案例。
更新:请注意,这个问题是关于创建子模块结构,而不是初始化它。