递归地对所有git子模块进行git

递归地对所有git子模块进行git

本文介绍了递归地对所有git子模块进行git pull的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的个人存储库有一些存储库作为子模块.以及以下命令

My personal repository has some repositories as submodules. And the following command

$ git submodule foreach git pull origin master

在进入ruby存储库后立即遇到以下结果,因为ruby存储库似乎没有master分支,并且"git pull"已停止.

was faced with the following result right after entering ruby repository because ruby repository seems that it does not have a master branch and "git pull" stopped.

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提供的一个命令行就能做到这一点.

So my question is what should I do to git pull for all of submodules only by git command? Should I do make a script to this? I hope just ONE command line provided from git will make this.

推荐答案

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.

git submodules are typically in detached-HEAD states, and thus git pull on them can't figure out what you mean when it comes to the merge phase. If all you are trying to do is get the latest changes into the repository, try git submodule foreach git fetch instead. If you want to get each submodules master updated to its respective origin/master, then you can follow up with git submodule foreach git checkout master; git submodule foreach git merge origin/master.

然后,当然,您需要确定希望主存储库使用的每个子模块的版本(我不建议您一直盲目使用origin/master-这可能很不稳定-最好选择一个已知的-好的标签之类的东西),请在子模块中检出那些版本,然后在主存储库中跟上相应的git addgit commit.

Then, of course, you need to decide what version of each submodule you want your main repository to use (I would not recommend blindly going with origin/master all the time - it may be unstable - better to pick a known-good tag or something), check out those versions in the submodules, and follow up with the appropriate git adds and git commit in your main repository.

这篇关于递归地对所有git子模块进行git pull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 03:29