处于分离的HEAD状态时,如何将子模块更新为最新提交?

时间:2020-01-12 14:52:08

标签: git

我正在尝试更新子模块,以便它们使用更新的提交。

当我们使用子模块时,它们应该保持处于分离的头部状态。很好。

$ cd myproject
$ cd otherlibrary
$ git status .
HEAD detached from 091eccc
nothing to commit, working tree clean

我在otherlibrary中做了一些工作,现在我想更新myproject,以便它可以在otherlibrary中使用这些新的提交。这意味着,我需要以某种方式“更新子模块”。

这不起作用:(看?它仍然具有相同的提交号)

$ cd myproject
$ cd otherlibrary
$ git submodule update --remote
$ git status .
HEAD detached from 091eccc
nothing to commit, working tree clean

为完整起见,我也像这样git submodule update --rebase --remote和这样git submodule update --merge --remote那样尝试,但这没有什么区别。

我还阅读了这两篇有关该主题的SO文章,但是我的问题并不能因此解决:

1 个答案:

答案 0 :(得分:0)

phd noted in a comment一样,要使用git submodule update,您必须在超级项目中

git submodule update --remote所做的全部工作是cd进入子模块,运行git fetch,然后运行git checkout,因此如果您不想弹出来出于某种原因进入超级项目,您可以自己运行git fetchgit checkout。如果这样做,则可以在获取结果中四处浏览,并仔细选择所需的特定提交,而不是仅取origin/master所标识的那个,当然,如果您想要的那个是,则取origin/master所标识的那个,git submodule update --remote就是方便。)