1

I'm having trouble getting git's submodules to update properly when I pull a repository and the submodule's commit has changed. First off, I believe this question is different from this question because that question is concerned with staying up to date with a particular branch. I don't want the latest commit on a branch, I want the commit specified in the parent repository.

Here's my scenario:

Git repo A has repo B as a submodule. Repo A lists submodule B as being on commit abc.

Then, inside repo A, I do a git pull and receive a new commit for repo A. This new commit states that submodule B should now be on commit def. I run a git submodule update just to make sure everything is up to date.

Now here's where the problem arises.

I cd into submodule B and run git status. It reports HEAD detached at abc. Hmm, that's not right, it should be on def. But here's the confusing part - I run git log and the very first commit it lists is def, preceded by abc! How can that be? Shouldn't git log always start with HEAD? And if it knows about the new commit, why hasn't the working copy updated to reflect that?

Even after getting the submodule in the state described above, I can't figure out what git submodule ... command, if any, would move the B's head to be at def. The only fix I found was to cd into B and manually run git checkout def.

Help, please! I want a git pull in repo A to update submodule B to the commit has as indicated by A.

J-bob
  • 8,380
  • 11
  • 52
  • 85
  • 1
    You can selectively shut off submodule updating, did you do that and forget? `git config --list` and look for submodule update options. – jthill Dec 31 '20 at 21:56
  • If you did `git submodule update` update after `git pull`, your submodule repo should have `def` checked out. Or, just do `git pull --recurse-submodules`. I think `git status` saying "HEAD detached at abc" is what's confusing: what it means is "HEAD used to be at `abc`, but it's not anymore". It's very confusing! So I prefer to just do `git status` in the superproject. If all is clean, it means all submodules are checked out at the commit recorded in the currently checked out superproject commit. – philb Jul 12 '21 at 15:46
  • I checked the Git source code, and it seems that if what I say above is what's happening, `git status` in the submodule should say "detached from abc" (in contrast to "detached at abc". – philb Jul 12 '21 at 16:48

0 Answers0