我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。
如何获取所有git子模块的最新更改?
我们使用git子模块来管理一些依赖于我们开发的许多其他库的大型项目。每个库都是一个单独的repo,作为子模块引入到依赖项目中。在开发过程中,我们经常想要获取每个依赖子模块的最新版本。
如何获取所有git子模块的最新更改?
当前回答
如果是第一次签出回购,则需要使用--init first:
git submodule update --init --recursive
对于git1.8.2或更高版本,添加了选项--remote以支持更新到远程分支的最新提示:
git submodule update --recursive --remote
这还有一个额外的好处,那就是尊重.gitmodules或.git/config文件中指定的任何“非默认”分支(如果您碰巧有,默认值是origin/master,在这种情况下,这里的一些其他答案也会起作用)。
对于git 1.7.3或更高版本,您可以使用(但以下关于更新仍然适用的问题):
git submodule update --recursive
or:
git pull --recurse-submodules
如果您希望将子模块拉到最新的提交,而不是repo指向的当前提交。
详见git子模块(1)
其他回答
我不知道这是从哪个版本的git开始工作的,但这就是您正在搜索的:
git submodule update --recursive
我也使用git pull来更新根存储库:
git pull && git submodule update --recursive
注:这是从2009年开始的,当时可能不错,但现在有更好的选择。
我们使用这个。它叫git pup:
#!/bin/bash
# Exists to fully update the git repo that you are sitting in...
git pull && git submodule init && git submodule update && git submodule status
只需将其放在合适的bin目录(/usr/local/bin)中。如果在Windows上,您可能需要修改语法以使其正常工作:)
更新:
作为对原作者关于插入所有子模块的所有HEAD的评论的回应,这是一个很好的问题。
我很确定git内部没有这个命令。为了做到这一点,您需要确定HEAD对于子模块的真正含义。这可能很简单,比如说master是最新的分支,等等。。。
接下来,创建一个简单的脚本,执行以下操作:
检查git子模块状态以查找“已修改”的存储库。输出行的第一个字符表示这一点。如果子回购被修改,您可能不想继续。对于列出的每个回购,将其cd到其目录中,并运行gitcheckout-master和gitpull。检查错误。最后,我建议您向用户打印一个显示,以指示子模块的当前状态——也许会提示他们添加全部并提交?
我想指出的是,这种风格并不是git子模块的设计初衷。通常,你想说“LibraryX”的版本是“2.32”,在我告诉它“升级”之前,它会一直这样。
从某种意义上说,这就是您使用所描述的脚本所做的事情,但只是更加自动。需要小心!
更新2:
如果您使用的是windows平台,您可能需要考虑使用Python来实现脚本,因为它在这些方面非常有用。如果您使用的是unix/linux,那么我建议您使用bash脚本。
需要澄清吗?只需发表评论。
git pull --recurse-submodules --jobs=10
git在1.8.5中首次学习的特性。
在修复错误之前,第一次需要运行
git子模块更新--init--递归
第一次
克隆和初始化子模块
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
注意:最后两个命令具有相同的行为
在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目录中,最适合我。
这将拉动所有最新的子模块。