git-submodules - git submodule update 只需要最初?

标签 git-submodules

我掌握了 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-1HEAD 前面显示“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/

    相关文章:

    git - 如何在github上上传本地子模块的文件?

    Git 子模块是脏的?

    ruby-on-rails - 在两个 Rails 项目之间共享模型 - 使用 git 子模块?

    git - 为微服务存储子模块,但仍然使用 fork

    Git 历史包括/交错子模块提交

    git - Jenkins git 子模块更新失败

    windows - 如何跟踪不同目录中的 git 存储库?

    从接收后 Hook 更新 Git 子模块

    git - 如何在 git-buildpackage 中启用子模块克隆

    git - 自动将所有子模块添加到仓库