提取所有 git 子模块的最新版本的简单方法 [英] Easy way to pull latest of all git submodules
问题描述
我们正在使用 git 子模块来管理几个依赖于我们开发的许多其他库的大型项目.每个库都是一个单独的存储库,作为子模块引入依赖项目.在开发过程中,我们经常只想去抓取每个依赖子模块的最新版本.
We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule.
git 是否有内置命令来执行此操作?如果没有,Windows 批处理文件或类似的文件如何?
Does git have a built in command to do this? If not, how about a Windows batch file or similar that can do it?
推荐答案
如果是第一次检出一个repo,你需要先使用--init
:
If it's the first time you check-out a repo you need to use --init
first:
git submodule update --init --recursive
git 1.8.2及以上版本,新增--remote
选项,支持更新远程分支最新提示:
For git 1.8.2 or above, the option --remote
was added to support updating to latest tips of remote branches:
git submodule update --recursive --remote
这有一个额外的好处,即尊重 .gitmodules
或 .git/config
文件中指定的任何非默认"分支(如果你碰巧有任何,默认是 origin/master,在这种情况下,这里的其他一些答案也适用).
This has the added benefit of respecting any "non default" branches specified in the .gitmodules
or .git/config
files (if you happen to have any, default is origin/master, in which case some of the other answers here would work as well).
对于 git 1.7.3 或更高版本,您可以使用(但以下关于更新的问题仍然适用):
For git 1.7.3 or above you can use (but the below gotchas around what update does still apply):
git submodule update --recursive
或:
git pull --recurse-submodules
如果你想把你的子模块拉到最新的提交而不是当前提交的 repo 指向.
if you want to pull your submodules to latest commits instead of the current commit the repo points to.
参见 git-submodule(1) 详情
这篇关于提取所有 git 子模块的最新版本的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!