git git子模块更新不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24634092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:11:55  来源:igfitidea点击:

git submodule update not functioning

git

提问by Luís de Sousa

I have a repository with various nested submodules. Committing and pushing works pretty well and the changes are visible at GitHub as expected.

我有一个包含各种嵌套子模块的存储库。提交和推送工作得很好,而且更改在 GitHub 上按预期可见。

In the testing/production environments, new releases of this project are being deployed using these commands:

在测试/生产环境中,正在使用以下命令部署此项目的新版本:

git pull --recurse-submodules
git submodule update --init --recursive

But this only updates the root project, none of the submodules are updated to the commits associated with the HEAD at GitHub. So far the only way I have found to update the whole project is to run git pullinside each individual submodule folder.

但这只会更新根项目,没有任何子模块更新到与 GitHub 上的 HEAD 关联的提交。到目前为止,我发现更新整个项目的唯一方法是git pull在每个单独的子模块文件夹中运行。

I understand that git submodule updateis the method referenced in most places, but it is not really producing any results in this case. What could be the cause?

我知道这git submodule update是大多数地方引用的方法,但在这种情况下它并没有真正产生任何结果。可能是什么原因?

回答by VonC

You need to make sure your submodules are following a branch, or they will only be checked out at a specific SHA1 (not at the latest of a branch, but the special entry of the index of your parent repo)

您需要确保您的子模块跟随一个分支,否则它们只会在特定的 SHA1 被检出(不是在分支的最晚,而是在您的父 repo 索引特殊条目

See "Git submodules: Specify a branch/tag" in order to make your submodule follow a branch.

请参阅“ Git 子模块:指定分支/标签”以使您的子模块跟随一个分支。

Then a git submodule update --init --recursive --remotewould be enough to check out the latest from that branch.

那么 agit submodule update --init --recursive --remote就足以检查该分支的最新情况。

This (git submodule update -remote) requires git 1.8.2+ March 2013. The OP Luís de Sousahas a git 1.7.9.5(March 2012) which doesn't offer this feature.

这 ( git submodule update -remote) 需要 git 1.8.2+ 2013 年 3 月。OP Luís de Sousa有一个 git 1.7.9.5(2012 年 3 月),它不提供此功能。

回答by Knut

You have a specific version committed to your repository. For git the submodules are "files" containing a sha1-hash of the version you provided. git submodule update --init --recursiveensures that your submodule is available in exactly that version.

您已将特定版本提交到您的存储库。对于 git,子模块是包含您提供的版本的 sha1-hash 的“文件”。git submodule update --init --recursive确保您的子模块在该版本中可用。

For example:

例如:

  • You make a git initon a directory and have a empty repo
  • You add a submodule using git submodule addwhich will record the current masters sha1-hash of that repo you are adding in your own repository
  • Multiple commits are made to the submodule but your repo will still contain that one hash you had as you added the submodule
  • If you make a git pullin the submodule you will get the new commits and have an uncommitted change in your own repository (the new sha1-hash of the submodules master)
  • As soon as you commit that change you are "pinning" the current version of the submodule
  • git submodule updatewill now enforce the new version is there
  • git init在一个目录上创建一个并且有一个空的仓库
  • 您添加一个子模块,使用git submodule add它将记录您在自己的存储库中添加的该存储库的当前主节点 sha1-hash
  • 对子模块进行了多次提交,但您的存储库仍将包含您在添加子模块时拥有的一个哈希值
  • 如果您git pull在子模块中创建一个,您将获得新的提交并在您自己的存储库中有一个未提交的更改(子模块 master 的新 sha1-hash)
  • 一旦您提交该更改,您就会“固定”子模块的当前版本
  • git submodule update现在将强制执行新版本在那里

So if some other contributor of your own repository updates his checkout and does a git submodule updatehe will get the version you pinned. So in general the submodule update will do some work only when the submodule is not checked out or if someone changed the associated hash in your repository.

因此,如果您自己存储库的其他一些贡献者更新了他的 checkout 并执行了 a,git submodule update他将获得您固定的版本。因此,通常只有当子模块未检出或有人更改了存储库中的关联哈希时,子模块更新才会执行一些工作。