git子模块卡在错误的提交中(“子模块更新"不起作用) [英] A git submodule is stuck at wrong commit ('submodule update' doesn't work)
问题描述
我有一个带有子模块的父项目(没有嵌套的子模块).子模块有一个新的提交(我们称它为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 update
和git 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. 这是因为这样做会强制主存储库更新 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.
我必须在子模块中进行一些更改,因此我手动切换到正确的提交,在子模块中进行并提交了更改,并在父项目中提交了子模块.
最终,这更新了对子模块的引用.
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提交.
Pushing that will publish that new gitlink commit.