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


当前回答

由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 {}

其他回答

在我的例子中,在删除了.git目录下的所有删除引用文件之后,问题就解决了。

如果您查看消息,它会告诉您需要删除哪些文件(特别是)。

要删除的文件位于.git/refs/remotes下。

我刚刚删除了那里的所有文件,并运行了gc prune

git gc --prune=now

之后,一切正常。

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

尝试以下操作:gitbranch--取消上游设置

我之前遇到过这个问题,但当我在终端上看到这个命令时,我刚刚解决了这个问题。

尝试使用以下方法清理本地存储库:

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

man git gc(1):

git-gc - Cleanup unnecessary files and optimize the local repository

git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]

       Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
       (to reduce disk space and increase performance) and removing unreachable objects which may have been
       created from prior invocations of git add.

       Users are encouraged to run this task on a regular basis within each repository to maintain good disk
       space utilization and good operating performance.

man git远程(1):

git-remote - manage set of tracked repositories

git remote prune [-n | --dry-run] <name>

           Deletes all stale remote-tracking branches under <name>. These stale branches have already been
           removed from the remote repository referenced by <name>, but are still locally available in
           "remotes/<name>".            

如果“无法更新本地参考”的错误再次出现,即使在应用Vojtech Vitek或Michel Krämer的答案后,您也可能在本地AND主存储库中有错误的参考。

在这种情况下,您应该应用两个修复程序,而不需要在两者之间拉或推。。。

rm .git/refs/remotes/origin/master
git fetch
git gc --prune=now
git remote prune origin

只有在推/拉之前应用两个修复程序后,我才能获得永久解决方案。