使用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远程梅干起源,但没用。


当前回答

写下可能导致此问题的具体案例。

有一天,我推送了一个名为“feature/subfeature”的分支,同时在远程拥有“feature”分支。

该操作在我这边运行良好,没有任何错误,但当我的同事提取和/或提取任何分支时,他们都收到了完全相同的错误消息:无法更新本地ref,无法锁定ref的refs/remotes/origin/feature/subfeature。

这是通过删除remote上的功能分支(git push--delete origin功能),然后在我同事的repo上运行git remote prune origin来解决的,这会生成包含*[pruned]origin/feature的消息。

所以,我猜git fetch试图在git内部(.git/…)的功能文件夹中创建子功能引用,但创建文件夹失败,因为已经有了功能引用。

其他回答

我只是想补充一下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。

从项目中手动删除特定分支的文件

.git/refs/remotes/origin/master
 git gc --prune=now
 git pull

今天刚遇到问题。

故障排除方法:使用Windows服务器上的SourceTree,您可以尝试以管理员身份运行它。这解决了我在域中Windows Server 2012 R2上的Atlassian源树2.1.2.5上“无法更新本地引用”的问题。

如果您也可以复制这种情况,则证明问题是由权限问题引起的。最好深入研究并找到根本原因-可能某些特定文件是由其他用户等拥有的-否则会有一个不受欢迎的副作用:您将不得不以管理员身份运行SourceTree。

由Google Drive desktop.ini文件引起时

用于Windows的Google Drive客户端在每个文件夹中创建desktop.ini文件。如果您的git存储库位于正在与Google Drive同步的目录中,则desktop.ini文件将导致git存储失败,出现以下情况:

cannot lock ref 'refs/remotes/origin/desktop.ini': unable to resolve reference 'refs/remotes/origin/desktop.ini': reference broken

要解决此错误,您可能需要删除git存储库中的desktop.ini文件。

如果安装了WSL,则可以使用以下命令删除desktop.ini文件:

注:⚠️ 此命令将删除<project_directory>中所有.git目录中的所有desktop.ini文件。

find <project_directory> -type d -name .git -print0 | xargs -0 -I {} find {} -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}

如果只想删除特定.git目录中的desktop.ini文件,则可以使用以下命令:

find <.git_directory> -type f -name desktop.ini -print0 | xargs -0 -I {} rm -vf {}

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

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

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