我的项目结构
ProjectA
-FrameworkA (submodule)
--Twig (submodule of FrameworkA)
如何递归更新子模块?我已经尝试了一些 git 命令(在 ProjectA 根目录上)
git submodule foreach git pull origin master
或者
git submodule foreach --recursive git pull origin master
但无法提取 Twig 的文件。
我的项目结构
ProjectA
-FrameworkA (submodule)
--Twig (submodule of FrameworkA)
如何递归更新子模块?我已经尝试了一些 git 命令(在 ProjectA 根目录上)
git submodule foreach git pull origin master
或者
git submodule foreach --recursive git pull origin master
但无法提取 Twig 的文件。
git submodule update --recursive
您可能还想使用 --init 选项,这将使它初始化任何未初始化的子模块:
git submodule update --init --recursive
注意:在某些旧版本的 Git中,如果您使用该--init选项,可能不会更新已经初始化的子模块。在这种情况下,您还应该运行不带--init选项的命令。
我使用的方式是:
git submodule update --init --recursive
git submodule foreach --recursive git fetch
git submodule foreach git merge origin master
由于您的子模块的默认分支可能不是 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'
在最近的 Git(我使用的是 v2.15.1)中,以下内容将递归地将上游子模块更改合并到子模块中:
git submodule update --recursive --remote --merge
您可以添加--init以初始化任何未初始化的子模块,并--rebase在您想要变基而不是合并时使用。
您需要在之后提交更改:
git add . && git commit -m 'Update submodules to latest revisions'