git submodule update needed only initially?
Asked Answered
G

1

14

I'm getting a hang of git submodule (wishful thinking?) and I'm coming up with more specific questions, which is a good sign...

I've tried to find the which revision of the submodule the superproject refers to, in .gitmodules and .git/config, but nothing is mentioned there...
The scenario is that I'm changing submodules in their root locations (from which they're imported), and then pulling them in where they're "submoduled"...
Beyond committing from the superproject to incorporate those changes into the superproject repo, do I also need to do "git update" to register the new pulled in submodule commits?

Basically the question is:

do I need to "git submodule update" only when I first clone the superproject, or after every pulling of the submodule (from its own repo)?

Thank you

Gallicism answered 2/1, 2010 at 16:17 Comment(1)
Sorry for the late answer, I didn't see your new question after your previous one (stackoverflow.com/questions/1979167)Marlomarlon
M
28

As mentioned in my previous answer to git submodule update, that command checks out the specific version of the project, base on their .gitmodules file.

The GitPro page does insist:

This is an important point with submodules: you record them as the exact commit they’re at.

You can see which commit is referenced by running within the "super project" (the one referencing one or several submodules):

  • git submodule status (except if you did some commit directly within that submodule, in that case it will show a "+" in front of the SHA-1 of the HEAD of any submodule that has advanced from the SHA-1 stored in the superproject) or
  • git ls-files --stage looking for entry in mode "160000", a special entry in the Git index.

That means, each time you execute a git command in the "super project" which could modify that submodule commit SHA1, you need a "git submodule update".

do I need to "git submodule update" only when I first clone the superproject, or after every pulling of the submodule (from its own repo)?

Yes, you have to do this every time you pull down a submodule change in the main project.
That is because you are referencing the exact commit the submodule original repo is at (as said above), and when you pull that repo, you are effectively modifying that commit.

Marlomarlon answered 9/2, 2010 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.