git - 排除子模块的子模块

标签 git git-submodules

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

相关文章:

git-tf 在 checkin 时告诉我 "Could not lock";我该如何解决?

git - SourceTree - 使分支成为新的主人

git - 有没有办法使用 GPG key 在 Git 中提交 "autosign"?

django - 在 git 项目中创建子模块

git - 如何使用 Git 进行子模块稀疏 check out ?

git - 使用 git 分支作为过去学术研究实验的快照

git - 没有任何选项的 'git reset' 命令有什么作用?

Git - 查看具有相应哈希值的特定子模块的历史记录

github - 如何在 Travis CI 中添加 SSH key ?

git - 如何将 Git 中的文件添加到以前的子模块的路径中?