当我们在git存储库中有很多(比如20个)子模块时,我们可以像这样安装(和更新)它们:
git submodules update --init --recursive
Run Code Online (Sandbox Code Playgroud)
Git尝试在此命令后下载每个子模块(递归).如果我们想让一些子模块可选(如插件)怎么办?
我们怎样才能让git跳过默认下载这些可选子模块,并在我们标记这个子模块时处理为通常的子模块"好的,从现在开始使用"?
我有.gitmodules中的子模块列表.我想下载一个特定的子模块,即只有在配置文件中启用某个选项为true时才下载grpc.因为我的构建有时不需要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
Run Code Online (Sandbox Code Playgroud)
还有一种方法可以在执行命令时专门排除子模块:
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
我想在子模块更新时排除grpc中的grpc和子模块.就像是:
git submodule update --init --recursive "exclude third-party/grpc"
Run Code Online (Sandbox Code Playgroud)