3

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.

me76
  • 109
  • 1
  • 7
  • 1
    Even after manually pulling the submodule: can you the do a `cd ..; git add submodule` (no trailing slash, replace 'submodule' by the name of the root folder of that submodule), and check again? – VonC May 30 '19 at 22:57
  • 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. – me76 Jun 03 '19 at 02:26
  • If this happens again in the future, I will try your advice and will comment here. Thanks! – me76 Jun 03 '19 at 02:27
  • OK, I have edited the answer according to your comment, with an explanation. – VonC Jun 03 '19 at 04:33
  • So, it happened again yesterday. _git submodule add_ didn't work immediately, but then I found [this discussion](https://community.atlassian.com/t5/Sourcetree-questions/SourceTree-says-No-url-found-for-submodule-path/qaq-p/628869) where 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. – me76 Jun 21 '19 at 13:51

1 Answers1

0

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    The submodule commit `sha-new` is in the remote; the parent project is at the latest commit (that refers to submodule's `sha-new`); and `git ls-tree current-parent-branch` shows `160000 commit new-sha submodule`. – me76 May 30 '19 at 13:43
  • I've added some details regarding submodule's history. – me76 May 30 '19 at 14:51
  • @me76 OK, I have included your comment (with a note of mine) in the answer. – VonC Jun 21 '19 at 14:06