2012-04-16 816 views
171

我的项目strutureGit的子模块更新递归

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

如何更新子模块递归?我已经尝试过(上项目A根)

git submodule foreach git pull origin master 
or 
git submodule foreach --recursive git pull origin master 

一些git的命令,但不能拉枝条

的文件
+0

如何[混帐深(https://github.com/bluejamesbond/git-deep)? – bluejamesbond 2017-01-02 00:47:44

回答

374
git submodule update --recursive 

您也可能希望使用--init选项,这将使任何初始化未初始化的子模块:

git submodule update --init --recursive 

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

+0

如何递归添加子模块? “git子模块添加FrameworkA.git”只是拉取FrameworkA的文件。 – complez 2012-04-16 04:48:09

+1

你可以做一个“git submodule add blah”然后“git submodule update --init --recursive”。 – drewag 2012-04-16 13:37:58

+0

这是不是比我的方式不同? – 2013-09-26 13:30:21

18

我使用的方法是:

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

我改变了最后一行:'git submodule foreach git pull - 只支持原始主' – 2014-10-23 07:43:50

+1

我也会添加 - 递归到最后一行:“git submodule foreach --recursive git merge origin master”否则当它自己更新子模块时,您可以获得一个脏子模块。 – 2015-10-02 18:54:47

+0

过去三个小时一直在寻找这个。谢谢你,先生。 要添加到这一点,你也可以使用犯这些命令,如: 'git的子模块的foreach --recursive“git的承诺-a | :“'。无论结果如何,':'都会使其循环。见[链接](https://stackoverflow.com/questions/19728933/continue-looping-over-submodules-with-the-git-submodule-foreach-command-after)https://stackoverflow.com/questions/19728933 /继续套住-过子模块-与最GIT-子模块-的foreach-命令后。 – 2017-05-23 02:10:18

12

,因为它可能会发生,你的子模块的默认分支是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' 
+0

我尝试在我的[通用Makefile](https://github.com/Falkor/Makefiles/blob/devel/repo/Makefile)中添加这个命令,但我仍然陷入困境让GNU Make * ignore *解释$(...)序列,尽管它存在于简单引号内。任何人有想法? – 2014-03-19 13:57:05

+0

你的命令是我需要的,谢谢你!但我得到:'进入“核心” 致命的:模棱两可的说法“出身/ HEAD”:未知修订或路径不工作的tree.'其中'Core' 是子模块 – Sanandrea 2017-05-03 13:01:28

+0

有用的信息,谢谢你的分享! – 2017-07-04 19:09:18

0

在最近的Git(我使用v2.15.1),以下将合并上游子模块变成递归子模块:

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

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

您需要事后提交更改:

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