为什么“git submodule update”会跳过子模块?

kjo*_*kjo 5 git git-submodules

我有一个带有单个子模块的 git 存储库sub/x。(该子模块不包含其自己的任何子模块。)

在超级项目的存储库中, 的输出git status显示以下(未暂存的)修改

modified:   sub/x (new commits)
Run Code Online (Sandbox Code Playgroud)

如果我现在跑步

git submodule update
Run Code Online (Sandbox Code Playgroud)

...在超级项目上,以下行被打印到终端(仅此而已):

Skipping submodule 'sub/x'
Run Code Online (Sandbox Code Playgroud)

此后,git status超级项目的输出保持如上所示,没有变化。

(如果我添加--initgit submodule update命令中,则同上。)

问:如何确定git submodule update [--init]跳过sub/x子模块的原因?

tor*_*rek 10

(注意:我只检查了最新的 Git 版本,并且子模块代码一直在发生更改,因此这可能不是唯一的情况。但这是最新的 Git 中唯一可能出现该消息的地方。)

编辑2:当超级项目中.git/config有明确的设置时,似乎以下情况适用。update = none这比我下面的猜测更有意义;这是这里表达式的前半部分||。我假设没有update = none设置,但我们从后半部分得到了这个(未指定且类型=无),我仍然觉得这令人困惑。

(下面继续原答案)


此消息出现在Git 子模块帮助程序代码中:

        if (suc->update.type == SM_UPDATE_NONE
            || (suc->update.type == SM_UPDATE_UNSPECIFIED
                && update_type == SM_UPDATE_NONE)) {
                strbuf_addf(out, _("Skipping submodule '%s'"), displaypath);
                strbuf_addch(out, '\n');
                goto cleanup;
        }
Run Code Online (Sandbox Code Playgroud)

当超级项目中没有为给定子模块设置设置并且更新类型未指定(没有)时,此代码将触发。所以:submodule.name.update.git/configgit submodule update--checkout

git submodule update --checkout
Run Code Online (Sandbox Code Playgroud)

将覆盖此设置,就像将子模块的更新设置配置为checkout. 编辑:我不明白为什么代码是这样的:文档说默认值是checkout,并且与实际设置设置为checkout、 vs 默认为 的行为不同checkout,似乎与此声明不匹配。