git submodule update needed only initially?

2018-12-31 08:21发布

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

1条回答
荒废的爱情
2楼-- · 2018-12-31 08:53

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, thinat 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.

查看更多
登录 后发表回答