我掌握了 git submodule 的窍门(一厢情愿?),我想出了更具体的问题,这是一个好兆头......
我试图在 .gitmodules
中找到 super 项目所指的子模块的哪个版本。和 .git/config
,但没有提到那里...
场景是我正在更改其根位置(从中导入它们)中的子模块,然后将它们拉到它们“子模块”的位置......
除了从 super 项目提交以将这些更改合并到 super 项目存储库中之外,我是否还需要执行“git 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)?
谢谢
最佳答案
正如我之前对 git submodule update
的回答中所述,该命令检查项目的特定版本,基于他们的.gitmodules
文件。
GitPro page does insist :
This is an important point with submodules: you record them as the exact commit they’re at.
您可以通过在“ super 项目”(引用一个或多个子模块的那个)中运行来查看引用了哪个提交:
git submodule status
(除非您直接在该子模块中进行了一些提交,否则它将在从存储在 super 项目中的 +
的任何子模块的 SHA-1
的 HEAD
前面显示“SHA-1
” ) 或 git ls-files --stage
在模式“160000”中寻找条目,这是 Git 索引中的一个特殊条目。 这意味着,每次您在“ super 项目”中执行可以修改该子模块提交 SHA1 的 git 命令时,您都需要一个“
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)?
是的,每次您在主项目中拉下子模块更改时都必须这样做。
那是因为您正在引用子模块原始仓库所在的确切提交(如上所述),并且当您拉取该仓库时,您实际上是在修改该提交。
关于git-submodules - git submodule update 只需要最初?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1992018/