使用git 1.6.4.2时,当我尝试git pull时,会出现以下错误:

error: unable to resolve reference refs/remotes/origin/LT558-optimize-sql: No such file or directory
From git+ssh://remoteserver/~/misk5
 ! [new branch]      LT558-optimize-sql -> origin/LT558-optimize-sql  (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/split-css: No such file or directory
 ! [new branch]      split-css  -> origin/split-css  (unable to update local ref)

我尝试过git远程梅干起源,但没用。


当前回答

试试看:

git pull origin Branch_Name

Branch_Name,您当前所在的分支。

如果您只执行一个git pull,它也会提取所有其他创建的分支名称。

所以你得到这个的原因是:

! [new branch]      split-css  -> origin/split-css  (unable to update local ref)

其他回答

我也遇到了。在我的情况下,糟糕的裁判是大师,我做了以下事情:

rm .git/refs/remotes/origin/master
git fetch

这使得git恢复了ref文件。在那之后,一切又如愿以偿了。

我只是想补充一下Git引用损坏的可能原因之一。

可能的根本原因

在我的系统(Windows 7 64位)上,当BSOD发生时,一些存储的参考文件(最有可能是BSOD发生后当前打开/写入的)会被NULL字符(ASCII 0)覆盖。

正如其他人提到的,要修复它,只需删除那些无效的引用文件并重新获取或重新提取存储库就足够了。

实例

错误消息:

无法锁定引用“refs/remotes/origin/some/branch”:无法解析引用“refs/remotes/origin/some/bbranch”:引用已断开

解决方案:

删除存储在文件%repo_root%/.git/refs/remotes/origin/some/branch中的引用refs/remotes/corigin/sme/branch。

我也遇到过同样的问题,并通过查找出错的文件来解决:

\repo\.git\refs\remotes\origin\master

这个文件充满了null,我用github的最新引用替换了它。

git fetch--prune为我修复了这个错误:

[marc.zych@marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:25]
[I]> git fetch
error: cannot lock ref 'refs/remotes/origin/user/janek/integration/20170505': 'refs/remotes/origin/user/janek/integration' exists; cannot create 'refs/remotes/origin/user/janek/integration/20170505'
From github.com:zooxco/driving
 ! [new branch]            user/janek/integration/20170505 -> origin/user/janek/integration/20170505  (unable to update local ref)
From github.com:zooxco/driving
[marc.zych@marc-desktop] - [~/code/driving] - [Wed May 10, 02:58:30]
[I]> git fetch --prune
 - [deleted]               (none)     -> origin/user/janek/integration

不过,这假设有问题的分支已在远程删除。

您也可以将其添加到~/.gitconfig中,以在运行git fetch时自动修剪:

[fetch]
    prune = true

尝试了这些,但没有对我起作用:

$ git gc --prune=now
$ git remote prune origin
$ git fetch --prune

我不得不通过删除本地文件夹并再次克隆来解决这个问题。