Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

git submodule update needed only initially?

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...