为什么 git 无法为给定的提交获取特定的有效子模块以及如何修复它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42417294/
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-09 04:50:10  来源:igfitidea点击:

Why does git fail to fetch specific valid submodule for a given commit and how to fix it?

gitgit-submodulesgit-commit

提问by rbaleksandar

I have a gitrepo which has another one as a submoduledependency. In the root of my project (where the .git, .gitsubmodulesetc. are) I called

我有一个gitrepo,它有另一个作为submodule依赖项。在我的项目的根(其中.git.gitsubmodules等等都是)我叫

git submodule update

This failed with the following message:

这失败并显示以下消息:

Fetched in submodule path 'src/framework', but it did not contain cc8c38e9d853491c672452d8dbced4666fc73ec8. Direct fetching of that commit failed.

在子模块路径“src/framework”中获取,但不包含 cc8c38e9d853491c672452d8dbced4666fc73ec8。直接获取该提交失败。

where src/frameworkis a sub-directory of my project (PROJECT_ROOT/src/framework) and should be where the third-party repo lands. The given commit hash is a valid one.

wheresrc/framework是我的项目 ( PROJECT_ROOT/src/framework)的子目录,应该是第三方 repo 所在的位置。给定的提交哈希是有效的。

I have also tried git clone --recursive <my-repo>but it fails too.

我也尝试过,git clone --recursive <my-repo>但它也失败了。

The contents of my .gitmodulesis

我的内容.gitmodules

[submodule "src/framework"]
        path = src/framework
        url = [email protected]:gh/framework.git

In addition to that I have to note the following important fact: due to recent updates in the frameworkrepo my code breaks hence I really need to retrieve that specific version of it where things were working fine.

除此之外,我必须注意以下重要事实:由于frameworkrepo 中最近的更新,我的代码中断了,因此我真的需要检索它的特定版本,那里一切正常。

采纳答案by VonC

Yes, I can follow the link in my web browser (using GitLab)

是的,我可以点击我的网络浏览器中的链接(使用 GitLab)

Can you clone that repo though, with that commit included?
GitLab has permission levelwhich will restrict access, so make sure your git clone commands are executed with the right user, and with the ssh keys in said user home directory/.ssh.

你能克隆那个 repo 吗,包括那个提交?
GitLab 具有限制访问的权限级别,因此请确保您的 git clone 命令使用正确的用户执行,并且使用 .gitlab 中的 ssh 密钥user home directory/.ssh

If you cannot clone the submodule repo yourself (in any place on your local hard drive), that would explain the error message.

如果您无法自己克隆子模块存储库(在本地硬盘驱动器上的任何位置),这将解释错误消息。

The problem came from someone who has done a reset of the head to a commit prior to the one that was linked as a submodule in the repository I was working with. This rendered the reference invalid. I have no idea how to fix this

问题来自某人,他将头部重置为在我正在使用的存储库中作为子模块链接的提交之前的提交。这导致引用无效。我不知道如何解决这个问题

You can make sure the submodule follows a branch(here, for instance, master):

您可以确保子模块遵循一个分支(例如,这里是master):

cd /path/to/parent/repo
git config -f .gitmodules submodule.bar1.branch master

Then update the submodule at the last fetched commit master

然后在最后一次获取的提交时更新子模块 master

git submodule update --remote

The --remoteoptionensures that it will notuse the superproject's recorded SHA-1 to update the submodule, but will use the status of the submodule's remote-tracking branch instead.

--remote选项确保它不会使用超级项目记录的 SHA-1 来更新子模块,而是使用子模块的远程跟踪分支的状态。

That would avoid the "did not contain cc8c38e9d853491c672452d8dbced4666fc73ec8" error message.

这将避免“ did not contain cc8c38e9d853491c672452d8dbced4666fc73ec8”错误消息。

回答by Alim Giray Aytar

Running this command after cloning (and receiving the error) solved my problem:

克隆(并收到错误)后运行此命令解决了我的问题:

git submodule update --force --recursive --init --remote

Of course this is not a good solution. It is better to find and solve the underlying problem, but if anyone is in hurry, this was worked for me.

当然,这不是一个好的解决方案。最好找到并解决根本问题,但如果有人着急,这对我有用。

回答by EoghanM

The problem for me was that the submodule was pointing to a personal (clone of a) repository hosted on github.

我的问题是子模块指向托管在 github 上的个人(克隆)存储库。

I had multiple host repositories containing a reference to the same submodule. I had changed the HEAD of the submodule in one of those repositories and committed the repository. Unfortunately I had neglected to push the new submodule HEAD to github, so other instances of the repository didn't have a record of the latest head, even after git submodule updateetc.

我有多个包含对同一子模块的引用的主机存储库。我在这些存储库之一中更改了子模块的 HEAD 并提交了存储库。不幸的是,我忽略了将新的子模块 HEAD 推送到 github,因此存储库的其他实例没有最新 head 的记录,即使在git submodule update等之后也是如此。