git Git递归更新子模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10168449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:27:51  来源:igfitidea点击:

Git update submodules recursively

gitgit-submodules

提问by complez

My project struture

我的项目结构

ProjectA
-FrameworkA (submodule)
--Twig (submodule of FrameworkA)

How I can update submodules recursively? I already tried some git commands (on ProjectA root)

如何递归更新子模块?我已经尝试了一些 git 命令(在 ProjectA 根目录上)

git submodule foreach git pull origin master

or

或者

git submodule foreach --recursive git pull origin master

but cannot pull files of Twig.

但不能拉取 Twig 的文件。

回答by drewag

git submodule update --recursive

You will also probably want to use the --init option which will make it initialize any uninitialized submodules:

您可能还想使用 --init 选项,这将使其初始化任何未初始化的子模块:

git submodule update --init --recursive

Note: in some older versions of Git, if you use the --initoption, already-initialized submodules may not be updated. In that case, you should also run the command without --initoption.

注意:在一些旧版本的 Git 中,如果使用该--init选项,已经初始化的子模块可能不会更新。在这种情况下,您还应该运行不带--init选项的命令。

回答by William Entriken

The way I use is:

我使用的方式是:

git submodule update --init --recursive
git submodule foreach --recursive git fetch
git submodule foreach git merge origin master

回答by Sebastien Varrette

As it may happens that the default branch of your submodules are notmaster(which happens a lot in my case), this is how I automate the full Git submodules upgrades:

由于您的子模块的默认分支可能不是master(在我的情况下经常发生),这就是我自动化完整 Git 子模块升级的方式:

git submodule init
git submodule update
git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'

回答by mrts

In recent Git (I'm using v2.15.1), the following will merge upstream submodule changes into the submodules recursively:

在最近的 Git(我使用的是 v2.15.1)中,以下内容将递归地将上游子模块更改合并到子模块中:

git submodule update --recursive --remote --merge

You may add --initto initialize any uninitialized submodules and use --rebaseif you want to rebase instead of merge.

您可以添加--init以初始化任何未初始化的子模块,并--rebase在您想要变基而不是合并时使用。

You need to commit the changes afterwards:

您需要在之后提交更改:

git add . && git commit -m 'Update submodules to latest revisions'