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

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


当前回答

第一次

克隆和初始化子模块

git clone git@github.com:speedovation/kiwi-resources.git resources
git submodule init

Rest

在开发过程中,只需拉动并更新子模块

git pull --recurse-submodules  && git submodule update --recursive

将Git子模块更新为最新的提交源代码

git submodule foreach git pull origin master

首选方式如下

git submodule update --remote --merge

注意:最后两个命令具有相同的行为

其他回答

我想你必须写一个剧本才能做到这一点。老实说,我可能会安装python,这样您就可以使用os.walk来cd到每个目录并发出相应的命令。使用python或其他脚本语言(而不是批处理),可以轻松添加/删除子项目,而无需修改脚本。

在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目录中,最适合我。

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

第一次

克隆和初始化子模块

git clone git@github.com:speedovation/kiwi-resources.git resources
git submodule init

Rest

在开发过程中,只需拉动并更新子模块

git pull --recurse-submodules  && git submodule update --recursive

将Git子模块更新为最新的提交源代码

git submodule foreach git pull origin master

首选方式如下

git submodule update --remote --merge

注意:最后两个命令具有相同的行为

windows 2.6.3的Git:

git子模块更新--rebase--remote

从回购协议的顶层:

git submodule foreach git checkout develop
git submodule foreach git pull

这将切换所有分支机构以开发和拉动最新的