[英]How to update a submodule to latest commit when in detached HEAD state?
I am trying to update my submodules so that they use a more recent commit.我正在尝试更新我的子模块,以便它们使用更新的提交。
When we use submodules, they are supposed to remain in a detached head state.当我们使用子模块时,它们应该保持在一个分离的头部状态。 That's fine.
没关系。
$ cd myproject
$ cd otherlibrary
$ git status .
HEAD detached from 091eccc
nothing to commit, working tree clean
I did some work in otherlibrary
and now I'd like to update myproject
so that it will use these new commits in otherlibrary
.我在
otherlibrary
做了一些工作,现在我想更新myproject
以便它将在otherlibrary
使用这些新提交。 That means, I need to 'update the submodule' somehow.这意味着,我需要以某种方式“更新子模块”。
This doesn't work: (see? it's still has the same commit number)这不起作用:(看到了吗?它仍然具有相同的提交号)
$ cd myproject
$ cd otherlibrary
$ git submodule update --remote
$ git status .
HEAD detached from 091eccc
nothing to commit, working tree clean
For completeness, I also tried it like this git submodule update --rebase --remote
and like this git submodule update --merge --remote
and that doesn't make any difference.为了完整
git submodule update --rebase --remote
,我也尝试过像这个git submodule update --rebase --remote
和像这个git submodule update --merge --remote
,这没有任何区别。
I also read these two SO articles that talk about the subject, but my problem isn't solved by this:我还阅读了这两篇讨论该主题的 SO 文章,但我的问题并没有因此解决:
As phd noted in a comment , to use git submodule update
, you must be in the superproject .正如phd 在评论中指出的那样,要使用
git submodule update
,您必须在超级项目中。
(All git submodule update --remote
does is cd
into the submodule, run a git fetch
, and then run a git checkout
, so if you don't want to pop back up to the superproject for some reason, you can run the git fetch
and git checkout
yourself. If you do this, you can poke around in the fetch results and carefully choose the specific commit you'd like, rather than just taking the one identified by origin/master
or whatever. Of course, if the one you'd like is whichever one is identified by origin/master
, the git submodule update --remote
is convenient.) (所有
git submodule update --remote
所做的就是cd
进入子模块,运行git fetch
,然后运行git checkout
,因此如果您出于某种原因不想弹回超级项目,则可以运行git fetch
和git checkout
自己。如果你这样做,你可以在 fetch 结果中仔细选择你想要的特定提交,而不是仅仅采用由origin/master
或其他什么标识的那个。当然,如果那个您想要的是origin/master
标识的任何一个, git submodule update --remote
很方便。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.