git pull失败“无法解析引用”“无法更新本地引用”

git pull fails “unable to resolve reference” “unable to update local ref”

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

1
2
3
4
5
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 remote prune origin,但没有帮助。


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

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

man git-gc(1):

1
2
3
4
5
6
7
8
9
10
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-remote(1):

1
2
3
4
5
6
7
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>".


也发生在我身上。在我的情况下,糟糕的裁判是高手,我做了以下工作:

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

这使得git恢复了ref文件。之后,一切都按预期工作。


这为我做了工作:

1
git gc --prune=now


对我来说,它可以删除文件夹.git/refs/remotes/origin/中引发错误的文件。


试试吧:

1
2
3
4
5
git gc --prune=now

git remote prune origin

git pull


执行以下命令:

1
2
3
4
5
rm .git/refs/remotes/origin/master

git fetch

git branch --set-upstream-to=origin/master

Just in case, if you need to know what is
.git/refs/remotes/origin/master, you would read the Remotes section
in Git References.


就我而言,在删除目录.git下的所有删除参考文件后,问题已解决。

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

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

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

1
git gc --prune=now

之后,一切正常。


我遇到了同样的问题,并通过转到出现错误的文件来解决了这个问题:

1
2
3
epo\.git
efs
emotes\origin\master

该文件充满了空值,我将其替换为github上的最新参考。


我只想补充一下引用中断的情况。

可能的根本原因

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

正如其他人提到的,要对其进行修复,只需删除那些无效的参考文件并重新获取或重新拉动存储库就足够了。

错误:cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken

解决方案:删除文件%repo_root%/.git/refs/remotes/origin/some/branch


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

1
2
3
4
5
6
7
8
9
[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

但是,这假定有问题的分支已在远程上删除。


要在很短的时间内回答这个问题,当您的本地计算机具有有关远程服务器的某些信息,并且有人更改了某些使远程计算机且您的更改不同步的信息时,就会出现此问题。

我遇到这个问题是因为有人删除了远程分支,并再次使用相同的名称创建了分支。

要处理此类问题,请从远程进行拉取或获取。

1
git remote prune origin

或者,如果您使用的是任何GUI,请从远程获取。

enter image description here


如果git gc --prune=now不能帮助您。 (像我这样的倒霉)

我所做的是在本地删除该项目,然后重新克隆整个项目。


说明:您的远程仓库(在Github / bitbucket中)的分支似乎已被删除,尽管您的本地引用未更新并且指向不存在的引用。

为了解决这个问题:

1
2
3
git fetch --prune
git fetch --all
git pull

更多信息-来自Github文档的参考:

git-fetch - Download objects and refs from another repository

--all
Fetch all remotes.

--prune After fetching, remove any remote tracking branches which no longer exist on the remote.


尝试这个:

1
git pull origin Branch_Name

Branch_Name,您当前所在的分支。

如果仅执行git pull,则也会提取所有其他创建的分支名称。

这就是您得到这个的原因:

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


我能够与

1
git remote update --prune

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

在这种情况下,您应同时应用两个修订,而不能在两者之间拉或推。

1
2
3
4
rm .git/refs/remotes/origin/master
git fetch
git gc --prune=now
git remote prune origin

对我来说,永久的解决方案只有在推/拉之前应用了两个修订之后才实现。


对我来说,我有一个名为feature/phase2的本地分支,而远程分支名为feature/phase2/data-model。命名冲突是问题的原因,所以我删除了本地分支(如果需要保留任何名称,则可以重命名)


我有同样的问题。我按照以下步骤

1)将有问题的分支切换到其他分支

2)删除该分支

3)再次结帐。

注意:-您可以存储未提交的更改,然后重新放回。


我使用git prune origin并完成了工作。


1
2
3
4
5
6
7
8
9
10
11
12
13
 # remove the reference file of the branch"lost"
 rm -fv ./.git/refs/remotes/origin/feature/v1.6.9-api-token-bot-reader

 # get all the branches from the master
 git fetch --all

 # git will"know" how-to handle the issue from now on
 #     From github.com:futurice/senzoit-www-server
 # * [new branch]      feature/v1.6.9-api-token-bot-reader ->
 # origin/feature/v1.6.9-api-token-bot-reader

 # and push your local changes
 git push

今天刚遇到问题。

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

如果您也可以复制这种情况,则说明问题是由权限问题引起的。最好进行深入分析并找到根本原因-可能某些特定文件由其他用户拥有,如此-否则会有不受欢迎的副作用:在剩余的永恒时间内,您必须以SourceTree的身份运行。


使用SourceTree时遇到了这个问题。我试图再次拉开,并且奏效了。我想我太快了(结帐):)。

我的情况与发布者的情况有些不同,因为我的存储库相对合作,没有任何明显的损坏。


在删除存储库并使用相同名称创建存储库时,面临相同的问题。只有当我重新设置如下所示的远程URL时,它才起作用;

git remote set-url origin [GIT_REPO_URL]

验证远程URL:

1
git remote -v

现在,所有命令都应照常运行。


尝试从git bundle创建的文件克隆时出现此问题,其他答案均无效,因为我无法克隆存储库(因此git gc和删除/编辑文件是不可能的)。

但是,还有另一种方法可以解决此问题-.bundle文件的源文件始于:

1
2
3
4
5
6
# v2 git bundle
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d HEAD
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master

PACK.......p..x...Kj.0...: (and so on...)

只需用vim删除第四行即可解决此问题。


我在作曲家更新时遇到了同样的问题。但是对我来说,它只有在我清除了作曲家的缓存并删除了vendor文件夹的内容之后才起作用:

1
2
3
4
5
rm -rf vendor/*
git gc --prune=now
git pull
composer clear-cache
composer update my/package

写下可能导致此问题的特定案例。

有一天,我在远程具有"功能"分支的同时推了一个名为"功能/子功能"的分支。

该操作正常进行,没有出现任何错误,但是当我的同事获取和/或拉出任何分支时,他们都有完全相同的错误消息unable to update local refcannot lock ref 'refs/remotes/origin/feature/subfeature

通过删除remote(git push --delete origin feature)上的feature分支,然后在我的同事的仓库中运行git remote prune origin来解决此问题,该消息生成包括* [pruned] origin/feature的消息。

因此,我的猜测是git fetch试图在内部git的feature文件夹中创建subfeature ref(.git / ...),但是创建文件夹失败,因为已经有feature ref。


当Mac上的开发人员创建的分支名称中的分支符号大于">"时,我们遇到了此问题。

这在TeamCity和运行SourceTree的基于Windows的本地计算机上引起了问题。 BitBucket让它顺利通过而没有任何问题。

为了解决这个问题,用户删除了分支并重新创建了它。这很容易。


具有相同的msg,但具有目录,但在拉入时出现了失败的msg。

git --prone也没有帮助我。
原来有一个文件与远程创建的目录同名。

不得不去.git logs refs remotes origin并删除语言环境文件-然后再次拉,一切都很好。