2013-02-19 50 views
3

我的个人存储库有一些存储库作为子模块。而下面的命令递归地git拉所有的git子模块只需

$ git submodule foreach git pull origin master 

正进入红宝石库因为Ruby库似乎它不具有主分支和“混帐拉”停止后立即面临以下结果。

Entering 'rails' 
From git://github.com/rails/rails 
* branch   master  -> FETCH_HEAD 
Already up-to-date. 
Entering 'roo' 
From git://github.com/hmcgowan/roo 
* branch   master  -> FETCH_HEAD 
Already up-to-date. 
Entering 'ruby' 
fatal: Couldn't find remote ref master 
Stopping at 'ruby'; script returned non-zero status. 

所以我的问题是what should I do to git pull for all of submodules only by git command?应该怎么做让一个脚本这样做呢?我希望只有一个由git提供的命令行会做到这一点。

+1

如果你不想'git的子模块的foreach ...'停止时在子回购的一个出现错误只需添加'|| :'给命令,即'git submodule foreach'git pull origin master || :'' – 2013-02-20 08:13:13

回答

2

git子模块通常处于分离HEAD状态,因此它们上的git pull无法弄清楚在合并阶段您的意思。如果您所要做的只是将最新更改导入存储库,请尝试使用git submodule foreach git fetch。如果您想要将每个子模块master更新为其各自的origin/master,那么您可以跟进git submodule foreach git checkout master; git submodule foreach git merge origin/master

然后,当然,您需要决定您希望主存储库使用的每个子模块的版本(我不建议盲目地始终使用origin/master--它可能不稳定 - 选择已知优质更好标签或其他内容),请查看子模块中的这些版本,并在主要存储库中跟进相应的git addgit commit

4

只需添加|| true到您的子模块的命令:

git submodule foreach 'git commit -m "my commit message" || true' 
+0

辉煌,你摇滚的男人! – 2015-04-21 20:49:26