git 使用配置拉取 "recurse=true" 不更新所有子模块

git pull with config "recurse=true" doesn´t update all submodules

我有 运行 以下 git 命令来更新我的配置:

git config --global submodule.recurse true

.gitconfig 中的条目现在看起来像这样:

[submodule]
    recurse = true

我的期望是 git pull 之后也会更新我所有的子模块。但是运行宁

git submodule update --init –recursive

再次拉动后仍然更新了一些子模块。

我是否误解了配置设置的效果,或者是否存在 git 拉取仍然不会更新子模块的情况?

我复制了这个,没有发现任何问题。

复制步骤

制作子模块;

Horba@Horba MINGW64 ~/Source/Repos
$ mkdir MySubmodule
$ cd MySubmodule/
$ git init
Initialized empty Git repository in C:/Users/Horba/Source/Repos/MySubmodule/.git/
$ git commit --allow-empty -m "Init."
[master (root-commit) b54bb2d] Init.

制作遥控器;

Horba@Horba MINGW64 ~/Source/Repos
$ mkdir MyRemote
$ cd MyRemote/
$ git init
$ git commit -m "Init." --allow-empty
[master (root-commit) ce0c165] Init.
$ git submodule add ../MySubmodule/
Cloning into 'C:/Users/Horba/Source/Repos/MyRemote/MySubmodule'...
done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.
$ git add -A
$ git commit -m "Add submodule."
[master d2cf903] Add submodule.
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 MySubmodule

本地化;

Horba@Horba MINGW64 ~/Source/Repos
$ git clone --recurse-submodules  MyRemote/ MyLocal
Cloning into 'MyLocal'...
done.
Submodule 'MySubmodule' (C:/Users/Horba/Source/Repos/MySubmodule) registered for path 'MySubmodule'
Cloning into 'C:/Users/Horba/Source/Repos/MyLocal/MySubmodule'...
done.
Submodule path 'MySubmodule': checked out 'b54bb2d8f459816dbe634f7e94af273aab9f29b9'

对子模块做一些工作;

Horba@Horba MINGW64 ~/Source/Repos
$ cd MySubmodule/
$ git commit --allow-empty -m "Submodule work."
[master 4ce4c85] Submodule work.

更新远程子模块;

Horba@Horba MINGW64 ~/Source/Repos/MyRemote/MySubmodule (master)
$ git pull
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From C:/Users/Horba/Source/Repos/MySubmodule
   b54bb2d..4ce4c85  master     -> origin/master
Updating b54bb2d..4ce4c85
Fast-forward

$ cd ..
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   MySubmodule (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

$ git add -A
$ git commit -m "Update submodule."
[master eef0abb] Update submodule.
 1 file changed, 1 insertion(+), 1 deletion(-)

设置我们的配置选项;

Horba@Horba MINGW64 ~/Source/Repos/MyLocal (master)
$ git config --global submodule.recurse true

在本地拉递归;

Horba@Horba MINGW64 ~/Source/Repos/MyLocal (master)
$ git pull
Updating ce0c165..eef0abb
Fast-forward
 .gitmodules | 3 +++
 MySubmodule | 1 +
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 MySubmodule
Submodule path 'MySubmodule': checked out '4ce4c855986a56b5362c30b30ff4143d1d399f98'

$ gs
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

您的问题是 new 由 pull 引入的子模块不是由 git pull 创建的吗?如果是这样,那就是一个已知错误,请参阅 git help pull;

BUGS

Using --recurse-submodules can only fetch new commits in already checked out submodules right now. When e.g. upstream added a new submodule in the just fetched commits of the superproject the submodule itself can not be fetched, making it impossible to check out that submodule later without having to do a fetch again. This is expected to be fixed in a future Git version.