我意识到这个问题已经被问过几次了,但是不幸的是,旧问题下的所有解决方案都无法解决我的问题。本质上,我试图从远程存储库中提取信息,每次都遇到错误:
error: cannot lock ref 'refs/remotes/origin/photonic_link': unable to resolve reference 'refs/remotes/origin/photonic_link': reference broken
From https://gitlab.com/GXC_Dev/genxcomm-python-library
! [new branch] photonic_link -> origin/photonic_link (unable to update local ref)
现在,就解决问题而言,我不得不在一周前将分支从master切换到photonic_link,因为我拉错了分支(master)却没有意识到我应该在另外一个分支上工作。自切换分支以来,这也是我第一次尝试从存储库中提取信息。
正如我之前提到的,我已经尝试了其他答案中的解决方案,但没有一个对我有用。我已经尝试过git gc --prune=now
和git gc
,但是对于这两个命令我都得到以下响应:
error: bad ref for .git/logs/HEAD
error: bad ref for .git/logs/refs/heads/photonic_link
error: bad ref for .git/logs/refs/remotes/origin/photonic_link
fatal: bad object refs/heads/photonic_link
fatal: failed to run repack
然后我尝试了git rm -rf .git/logs/refs/remotes/origin/photonic_link
,但收到了致命错误:
fatal: pathspec '.git/logs/refs/remotes/origin/photonic_link' did not match any files
git rm -rf .git/refs/remotes/origin/photonic_link
也返回“与任何文件都不匹配”的错误,类似于上面的错误。
运行git fetch
返回以下内容:
remote: Enumerating objects: 215, done.
remote: Counting objects: 100% (215/215), done.
remote: Compressing objects: 100% (136/136), done.
remote: Total 215 (delta 119), reused 144 (delta 75)
Receiving objects: 100% (215/215), 69.08 KiB | 115.00 KiB/s, done.
Resolving deltas: 100% (119/119), completed with 8 local objects.
From https://gitlab.com/GXC_Dev/genxcomm-python-library
98878cb..cef33e7 RF_Link_Modeling -> origin/RF_Link_Modeling
256b31e..9b09944 bell_dev -> origin/bell_dev
9c5603e..6209abc master -> origin/master
error: cannot lock ref 'refs/remotes/origin/photonic_link': unable to resolve reference 'refs/remotes/origin/photonic_link': reference broken
! [new branch] photonic_link -> origin/photonic_link (unable to update local ref)
我最后尝试做的是从我的.git / packed-refs文件中手动删除包含photonic_link的行,但是那里不存在。有谁知道我该如何解决这个问题?
答案 0 :(得分:3)
这发生在我身上,因为我正在开发的虚拟机崩溃并使其文件系统处于某种不一致的状态。
对我有什么帮助:
git for-each-ref
出了什么问题。这将列出损坏的引用,它们看起来像 warning: ignoring broken ref refs/remotes/origin/HEAD
。rm -rf .git/refs/remotes/origin
。它没有看起来那么危险,因为您只在本地删除,而远程存储库仍然完好无损。git branch --set-upstream-to=origin/master master
git pull
应该可以工作了。答案 1 :(得分:0)
对我有用的是
git fsck
然后我在记事本++上复制了所有损坏的引用、丢失的引用、散列 1 不匹配问题等,如下所示
error: bad ref for .git/logs/refs/remotes/origin/Feature/PENTEST-Chnages
error: bad ref for .git/logs/refs/remotes/origin/Feature/MOTS-2382-SharingPortal
error: bad ref for .git/logs/refs/remotes/origin/Feature/MOTS-2764-kiosk-api-changes
然后我修改它们如下:
rm .git/logs/refs/remotes/origin/Feature/PENTEST-Chnages
rm .git/logs/refs/remotes/origin/Feature/MOTS-2382-SharingPortal
rm .git/logs/refs/remotes/origin/Feature/MOTS-2764-kiosk-api-changes
在 git 终端上运行它,这修复了我所有的引用。
拉一下就成功了。