为什么git子模块更新失败并显示“致命:远程错误:upload-pack:不是我们的引用"? [英] Why does git submodule update fail with "fatal: remote error: upload-pack: not our ref"?

查看:1930
本文介绍了为什么git子模块更新失败并显示“致命:远程错误:upload-pack:不是我们的引用"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个子模块的git repo.我尝试删除并添加有问题的子模块( scopatz的nanorc ),但是错误仍然存​​在删除并重新添加.当我将存储库克隆到新位置时,我会自动使用 git子模块更新--init --recursive 更新它,这是在此操作失败的情况下,但仅适用于此子模块...以下是带有 GIT_TRACE = 2 的命令的相关输出:

I have a git repo with multiple submodules. I have tried deleting and adding the submodule in question (scopatz's nanorc), however the error persists across the deletion and re-addition. When I clone the repo to a new location I automatically update it with git submodule update --init --recursive, which is when this fails, but only for this submodule... Below is the relevant output from the command with GIT_TRACE=2:

23:01:26.918691 run-command.c:1569      run_processes_parallel: preparing to run up to 1 tasks
23:01:26.933567 run-command.c:1601      run_processes_parallel: done
23:01:26.934373 run-command.c:646       trace: run_command: git gc --auto
23:01:26.966805 git.c:344               trace: built-in: git gc --auto
23:01:26.991059 git.c:344               trace: built-in: git rev-parse --local-env-vars
23:01:27.015684 git.c:344               trace: built-in: git rev-parse --local-env-vars
23:01:27.032282 git.c:344               trace: built-in: git symbolic-ref -q HEAD
23:01:27.053948 git.c:344               trace: built-in: git config --get branch.master.remote
23:01:27.073636 git.c:344               trace: built-in: git fetch origin 151d94a8754b0a612315fc191c5373cc0055c13d
23:01:27.079657 run-command.c:646       trace: run_command: git-remote-https origin https://github.com/scopatz/nanorc.git
23:01:28.441725 run-command.c:646       trace: run_command: git rev-list --objects --stdin --not --all --quiet
23:01:28.452267 run-command.c:646       trace: run_command: git fetch-pack --stateless-rpc --stdin --lock-pack --thin https://github.com/scopatz/nanorc.git/
23:01:28.467757 git.c:344               trace: built-in: git fetch-pack --stateless-rpc --stdin --lock-pack --thin https://github.com/scopatz/nanorc.git/
fatal: remote error: upload-pack: not our ref 151d94a8754b0a612315fc191c5373cc0055c13d
fatal: The remote end hung up unexpectedly
Fetched in submodule path 'submodules/nano', but it did not contain 151d94a8754b0a612315fc191c5373cc0055c13d. Direct fetching of that commit failed.

希望这里的人能帮上忙,这时我大部分时间迷路了.

hoping someone here can help, I'm mostly lost at this point.

===下面的解决方案步骤===

cd {submodule path}
git reset --hard origin/master
cd -
git clean -n
git add {submodule path}
git commit
git submodule update --init --recursive

没有错误,太棒了.

推荐答案

使用Git和子模块,您至少需要两个Git存储库.一种是您的"存储库-主要的存储库,Git将其称为 superproject .第二个Git存储库是其他一些Git存储库:一点都没有什么特别的.只是您的超级项目包含以下两个部分:

With Git and submodules, you start with a minimum of two Git repositories. One is "your" repository—the main one, which Git will call the superproject. The second Git repository is some other Git repository: there is nothing special about it at all. It's just that your superproject has in it these two parts:

  • 用于克隆子模块的指令.这样,例如,在 git子模块更新--init 期间,您的Git可以根据需要运行 git clone .

  • Instructions for cloning the submodule. That lets your Git run git clone if needed, during git submodule update --init for instance.

某些提交的原始哈希ID,该ID应该在其他Git存储库中.如果在其他Git存储库的克隆中适当地克隆或运行了 git fetch ,则主存储库将使用此原始文件运行 git checkout hash 哈希ID.

The raw hash ID of some commit that should be in that other Git repository. Your main repository will, after cloning or running git fetch if appropriate in your clone of the other Git repository, run git checkout hash using this raw hash ID.

您的超级项目要求哈希ID 151d94a8754b0a612315fc191c5373cc0055c13d ,您可以从

Your superproject is asking for the hash ID 151d94a8754b0a612315fc191c5373cc0055c13d in the Git repository you can clone from https://github.com/scopatz/nanorc.git. That commit simply does not exist in that repository, so it's not in any clone you make either.

您知道您的超级项目为何列出此提交哈希ID(即使它不存在)吗?(我当然不是.)您不能从他们的Git中获得它,因为他们没有它.这就是所有这些错误消息告诉您的内容.

Do you know why your superproject lists this commit hash ID, even though it does not exist? (I certainly don't.) You cannot get it from their Git, because they don't have it. That's what all these error messages are telling you.

您可以尝试在其他存储库(或Google)中搜索 151d94a8754b0a612315fc191c5373cc0055c13d (我刚刚在Google上尝试过,但找不到).或者,如果您不太在意 提交,请尝试告诉您自己的Git(您的超级项目),它应该得到一些 other 提交,即确实存在,因此您可以得到.

You can try searching other repositories (or Google) for 151d94a8754b0a612315fc191c5373cc0055c13d (I just tried with Google and they can't find it). Or, if you don't really care specifically for that commit, try telling your own Git—your superproject—that it should get some other commit, one that does exist and therefore you can get.

您会得到 个什么承诺?我不知道:这取决于您.请注意,您的超级项目的地方 where 列出了子模块中的原始提交哈希:在每个提交中.您可以在超级项目中 git checkout 进行一些提交,可能是某些分支的提示.然后,您可以进入子模块,选择所需的提交,然后在该子模块中使用 git checkout -毕竟这是另一个Git克隆,因此您可以在此处执行任何Git命令-签出所需的提交.然后,退出子模块(将目录更改回您的超级项目)并在子模块路径上运行 git add 并在 git commit 上记录新的所需哈希ID.现在,此新提交要求那个特定的哈希ID.

Which commit should you get? I have no idea: that's up to you. Note that the place where your superproject lists the raw commit hash from the submodule is: in each commit. You can git checkout some commit, probably the tip of some branch, in your superproject. Then you can enter the submodule, pick a commit you like, use git checkout in that submodule—it's another Git clone, after all, so you can do any Git command there—to check out the desired commit. Then, exit the submodule (change directories back to your superproject) and run git add on the submodule path and git commit to record the new desired hash ID. This new commit now asks for that particular hash ID.

这篇关于为什么git子模块更新失败并显示“致命:远程错误:upload-pack:不是我们的引用"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆