我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。

如何获取所有git子模块的最新更改?


当前回答

对我来说,git2.24.03,更新到.gitmodules中定义的远程分支的最新提交。

git子模块更新--递归--init

git子模块更新--递归--远程

git版本2.24.3(Apple git-128)

请注意:有人说过git pull-递归子模块与git子模块update-递归-远程相同。但根据我的测试,gitpull-recurse子模块可能不会更新为.gitmodules中定义的远程分支的最新提交。

其他回答

在init上运行以下命令:

git submodule update --init --recursive

在gitrepo目录中,最适合我。

这将拉动所有最新的子模块。

解释

git - the base command to perform any git command
    submodule - Inspects, updates and manages submodules.
        update - Update the registered submodules to match what the superproject
        expects by cloning missing submodules and updating the working tree of the
        submodules. The "updating" can be done in several ways depending on command
        line options and the value of submodule.<name>.update configuration variable.
            --init without the explicit init step if you do not intend to customize
            any submodule locations.
            --recursive is specified, this command will recurse into the registered
            submodules, and update any nested submodules within.

之后,您可以运行:

git submodule update --recursive

在gitrepo目录中,最适合我。

这将拉动所有最新的子模块。

以下内容在Windows上适用。

git submodule init
git submodule update

上面的答案很好,不过我们使用了git钩子来简化这一过程,但事实证明,在git2.14中,您可以将git-config子模块.recure设置为true,以便在您拉到git存储库时更新子模块。

如果所有子模块都在分支上,这会产生一个副作用,即推动所有子模块的更改,但如果您已经需要这种行为,这可以完成任务。

可通过以下方式完成:

git config submodule.recurse true

你现在需要做的只是一个简单的git结账

只需确保通过以下全局配置启用它:git-config--global submodule.recure true

对我来说,git2.24.03,更新到.gitmodules中定义的远程分支的最新提交。

git子模块更新--递归--init

git子模块更新--递归--远程

git版本2.24.3(Apple git-128)

请注意:有人说过git pull-递归子模块与git子模块update-递归-远程相同。但根据我的测试,gitpull-recurse子模块可能不会更新为.gitmodules中定义的远程分支的最新提交。