仅最初需要 git 子模块更新?
我正在掌握 git 子模块(一厢情愿的想法?)并且我提出了更具体的问题,这是一个好兆头......
我试图找到超级项目引用的子模块的哪个版本,在 .gitmodules
和 .git/config
中,但那里没有提到任何内容...
情况是,我正在更改根位置中的子模块(从中导入它们),然后将它们拉到“子模块”的位置...
除了从超级项目提交以将这些更改合并到超级项目存储库中之外,我是否还需要执行“git update
”来注册新拉入的子模块提交?
基本上问题是:
仅当我第一次克隆超级项目时,或者每次拉出子模块(从其自己的存储库)后,我是否需要“
git submodule update
”?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我之前对
git 子模块更新
的回答中提到的,该命令根据 .gitmodules 文件检查项目的特定版本。GitPro 页面确实坚持:
您可以通过在“超级项目”(引用一个或多个子模块的项目)中运行来查看引用了哪个提交:
git submodule status
(除非您直接在该子模块中进行了一些提交,在这种情况下它将在从SHA 前进的任何子模块的
存储在超级项目中)或HEAD
的SHA-1
前面显示“+
” -1git ls-files --stage
查找模式“160000”中的条目,这是 Git 索引中的特殊条目。这意味着,每次您在“超级项目”中执行可以修改该子模块提交 SHA1 的 git 命令时,您都需要一个“
git submodule update
”。是的,每次在主项目中下拉子模块更改时都必须执行此操作。
这是因为您正在引用子模块原始存储库所在的确切提交(如上所述),并且当您拉取该存储库时,您实际上正在修改该提交。
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:
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 theSHA-1
of theHEAD
of any submodule that has advanced from theSHA-1
stored in the superproject) orgit 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
".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.