我在 .gitmodules 中有子模块列表。 我想下载一个特定的子模块,即 grpc 只有在配置文件中启用了某些选项为 true 时。 由于我的构建有时不需要 grpc。 所有子模块都在第三方目录中。 所以 .gitmodules 就像:
[submodule "third-party/libzip"]
path = third-party/libzip
url = https://github.com/nih-at/libzip.git
[submodule "third-party/sqlite"]
path = third-party/sqlite
url = https://github.com/mackyle/sqlite.git
branch = sqlite-3.23.1
[submodule "third-party/grpc"]
path = third-party/grpc
url = https://github.com/grpc/grpc.git
还有一种方法可以在执行命令时专门排除子模块:
git submodule update --init --recursive
我想在子模块更新时排除 grpc 和 grpc 中的子模块。像这样的东西:
git submodule update --init --recursive "exclude third-party/grpc"
最佳答案
来自 git 帮助:
update
Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules. The "updating" can be done in several ways depending on command line options and the value of submodule..update configuration variable. Supported update procedures are:
...
...
When no option is given and
submodule.<name>.update
is set to none, the submodule is not updated.
所以设置update = none
在配置文件中。您还可以在 --
之后明确给出路径只更新特定的子模块。要即时执行此操作而不更改配置文件,@PrashantShubham 指出您可以:
git -c submodule."third-party/grpc".update=none submodule update --init --recursive
关于git - 如何从更新中排除特定的 git 子模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52179463/