我有 git repo,我在其中使用 extern/
中的 git 子模块链接我的一些依赖项目录假设我有一个依赖 A
作为子模块,位于 extern/A
.现在A
本身作为 git 子模块有一些依赖项。在 A
的 repo ,即例如。 A/test/data/X
.
现在,当我克隆我的 repo 并运行 git submodule update --init --recursive
,为了在 CI 服务器上构建它,或者我们曾经,我希望上面的命令忽略 exter/A/test/data/X
,因为它就像我不想要的1G数据。
然而,我的其他依赖项有一些有用的子模块,所以我不能跳过 --recursive
.有没有办法做到这一点?
最佳答案
您可以使用 submodule.<name>.update
配置变量以设置应更新的子模块,如此处所述
How to exclude a specific git submodule from update? .
如果要排除 A 中的子模块 X,则可以使用以下命令:
git -c submodule."X".update=none submodule update --init --recursive
注:这假设 repo A 中的子模块 X(它是 extern 的子模块)在整个 repo extern 中是唯一的(包括它的所有子模块,以及它们的子模块等等......)如果 X 不是唯一的,那么所有名为X 将在 repo extern 中被跳过。
您可以使用以下命令在克隆过程中跳过子模块:
$ git -c submodule."X".update=none clone --recurse-submodules <repository>
如果子模块位于存储库下的目录中,则相对于其存储库的相对路径应包含在子模块名称中。为避免混淆,您可以从
.gitmodules
获取子模块名称。存储库中的文件。考虑以下示例
.gitmodules
文件,[submodule "path/to/submodule_X"]
path = path/to/submodule_X
url = https://github.com/<user>/<repo>
[submodule "Y"]
path = Y
url = https://github.com/<user>/<repo>
如果要跳过子模块 X,则替换
<name>
在 submodule.<name>.update
有了这个"path/to/submodule_X"
.这同样适用于嵌套子模块。
关于git - 排除子模块的子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56745097/