A git submodule is stuck at wrong commit ('submodule update' doesn't work)

拈花ヽ惹草 提交于 2020-07-03 04:52:05

问题


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

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.

Why, and how to fix it?

git version 2.21.0.windows.1

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

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

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.


回答1:


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

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.


The OP me76 adds in the comments:

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.

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.


The OP also refers to this thread:

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

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.

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.



来源:https://stackoverflow.com/questions/56371564/a-git-submodule-is-stuck-at-wrong-commit-submodule-update-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!