git子模块卡在错误的提交中(“子模块更新"不起作用) [英] A git submodule is stuck at wrong commit ('submodule update' doesn't work)

查看:128
本文介绍了git子模块卡在错误的提交中(“子模块更新"不起作用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有子模块的父项目(没有嵌套的子模块).子模块有一个新的提交(我们称它为new-sha),父模块引用了远程回购中的那个提交(在Web浏览器中查看回购时,我可以看到submodule @ new-sha). 我已经拉出了父项目,并且它还引用了工作目录中的正确提交,如在git show输出中看到的:

I have a parent project with a submodule (no nested submodules). The submodule has a new commit (let's call it new-sha), and the parent refers to that commit in remote repo (I can see submodule @ new-sha when viewing the repo in web browser). I have pulled the parent project, and it also refers to the right commit in the working directory, as seen in git show output:

--- a/submodule
--- b/submodule
@@ -1 +1 @@
-Subproject commit old-sha
+Subproject commit new-sha

即父项目中的最新提交已将子模块更改为new-sha.但是,子模块中的git submodule updategit pull --recurse-submodules均未更新为new-sha,它们始终签出old-sha.

I.e. the latest commit in parent project has changed the submodule to new-sha. However, neither git submodule update nor git pull --recurse-submodules update to new-sha in the submodule, they always check out old-sha.

为什么以及如何解决?

git版本2.21.0.windows.1

git version 2.21.0.windows.1

一些其他信息:子模块在本地具有sha-new,但是其HEAD停留在sha-old.

Some additional information: the submodule has sha-new locally, but its HEAD is stuck at sha-old.

sha-new立即从sha-old派生,这是最后3次提交,也许这可以提供一个线索:

sha-new is immediately derived from sha-old, and here are the last 3 commits, maybe this can give a clue:

sha-new  == the top of submodule's branch used by parent project
sha-old  == HEAD
sha-xyz  == origin/HEAD

origin/HEAD行使我担心.即使在手动拉出子模块(cd submodule; git pull origin branch-name:branch-name)之后,origin/HEAD仍位于顶部的第三次提交.

The origin/HEAD line worries me. Even after manually pulling the submodule (cd submodule; git pull origin branch-name:branch-name) origin/HEAD stayed at third commit from top.

推荐答案

您需要确保新提交已推送到子模块远程存储库. ( .gitmodules URL行中列出的那个)

You need to make sure the new commit was pushed to the submodule remote repository. (the one listed in the .gitmodules URL line)

然后,您需要在主父回购本地克隆中执行git status,以检查它是否是最新的master分支以及

Then you need to do a git status within your main parent repo local clone, to check it is at the latest of the master branch and that git ls-tree does show the right submodule root tree commit.

OP me76 添加了

我解决"了完全不同.
我必须在子模块中进行一些更改,因此我手动切换到正确的提交,在子模块中进行并提交了更改,并在父项目中提交了子模块.
最终,这更新了对子模块的引用.

I "solved" it differently.
I had to do some changes in the submodule, so I manually switched to the right commit, did and committed the changes in submodule, and committed the submodule in the parent project.
This finally updated the reference to submodule.

这是因为这样做会强制主存储库更新 gitlink (索引中的特殊条目),以引用子模块主文件夹树的新提交.
推送将发布新的gitlink提交.

That is because doing so forces the main repository to update the gitlink (special entry in the index) to reference the new commit of the submodule main folder tree.
Pushing that will publish that new gitlink commit.

OP还引用了

该人在索引(git ls-files --stage | grep 160000)中具有(明显冲突的)子模块版本.

The person had (apparently conflicting) version of submodule in the index (git ls-files --stage | grep 160000).

从索引(git rm --cached)中删除它并用git submodule add重新添加它之后,我终于能够从父项目中更新子模块.

After removing it from index (git rm --cached) and re-adding it with git submodule add, I was finally able to update the submodule from the parent project.

注意:git rm --cached asubmoduleFolder不能以'/'结尾:您要删除gitlink(索引中的'160000'特殊条目).不是文件夹.

Note: the git rm --cached asubmoduleFolder must not ends with '/': you are removing a gitlink (the '160000' special entry in the index). Not a folder.

这篇关于git子模块卡在错误的提交中(“子模块更新"不起作用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆