仅最初需要 git 子模块更新?

发布于 2024-08-16 09:47:35 字数 427 浏览 8 评论 0原文

我正在掌握 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花心好男孩 2024-08-23 09:47:35

正如我之前对 git 子模块更新 的回答中提到的,该命令根据 .gitmodules 文件检查项目的特定版本。

GitPro 页面确实坚持

这对于子模块来说很重要:您将它们记录为它们所在的确切提交。

您可以通过在“超级项目”(引用一个或多个子模块的项目)中运行来查看引用了哪个提交:

  • git submodule status (除非您直接在该子模块中进行了一些提交,在这种情况下它将在从 SHA 前进的任何子模块的 HEADSHA-1 前面显示“+” -1 存储在超级项目中)或
  • git ls-files --stage 查找模式“160000”中的条目,这是 Git 索引中的特殊条目。

这意味着,每次您在“超级项目”中执行可以修改该子模块提交 SHA1 的 git 命令时,您都需要一个“git submodule update”。

仅当我第一次克隆超级项目时,或者每次拉取子模块(从其自己的存储库)后,我是否需要“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:

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, in that 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文