如何从更新中排除特定的git子模块?

问题描述 投票:3回答:1

我有.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

还有一种方法可以在执行命令时专门排除子模块:

git submodule update --init --recursive

我想在子模块更新时排除grpc中的grpc和子模块。就像是:

git submodule update --init --recursive "exclude third-party/grpc"
git version-control git-submodules
1个回答
7
投票

从git帮助:

更新

通过克隆缺失的子模块并更新子模块的工作树,更新已注册的子模块以匹配超级项目所期望的内容。 “更新”可以通过多种方式完成,具体取决于命令行选项和子模块.update配置变量的值。支持的更新程序包括:

...

...

如果没有给出选项且submodule.<name>.update设置为none,则子模块不会更新。

所以在配置文件中设置update = none。您还可以在--之后显式提供路径,以仅更新特定的子模块。要在运行中执行此操作而不更改配置文件,@ PrashantShubham会注意到您可以:

git -c submodule."third-party/grpc".update=none submodule update --init --recursive
© www.soinside.com 2019 - 2024. All rights reserved.