git pull 失败“无法解析引用”“无法更新本地引用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2998832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git pull fails "unable to resolve reference" "unable to update local ref"
提问by Gabrielle
Using git 1.6.4.2, when I tried a git pull
I get this error:
使用 git 1.6.4.2,当我尝试 a 时出现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)
I've tried git remote prune origin
, but it didn't help.
我试过了git remote prune origin
,但没有帮助。
回答by Vojtech Vitek
Try cleaning-up your local repository with:
尝试使用以下命令清理本地存储库:
$ git gc --prune=now
$ git remote prune origin
man git-gc(1):
人 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-remote(1):
人 git-remote(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>".
回答by Michel Kr?mer
Happened to me as well. In my case, the bad ref was master, and I did the following:
也发生在我身上。就我而言,错误的裁判是大师,我做了以下事情:
rm .git/refs/remotes/origin/master
git fetch
This made git restore the ref file. After that everything worked as expected again.
这使得 git restore ref 文件。之后,一切都再次按预期工作。
回答by Bernd
This did the job for me:
这为我完成了工作:
git gc --prune=now
回答by Brian van Rooijen
For me, it worked to remove the files that are throwing errors from the folder .git/refs/remotes/origin/
.
对我来说,它可以从文件夹中删除抛出错误的文件.git/refs/remotes/origin/
。
回答by annelorayne
Try it:
尝试一下:
git gc --prune=now
git remote prune origin
git pull
回答by Matias Sebastiao
Execute the following commands:
执行以下命令:
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 Remotessection in Git References.
以防万一,如果您需要知道是什么
.git/refs/remotes/origin/master
,您可以阅读Git References 中的Remotes部分。
回答by David Ferenczy Rogo?an
I just would like to add how it may happen that a reference breaks.
我只想补充一下引用中断是如何发生的。
Possible root cause
可能的根本原因
On my system (Windows 7 64-bit), when a BSODhappens, some of the stored reference files (most likely currently opened/being written into when BSOD happened) are overwritten with NULL
characters (ASCII 0).
在我的系统(Windows 7 64 位)上,当BSOD发生时,一些存储的参考文件(最有可能在 BSOD 发生时当前打开/写入)被NULL
字符(ASCII 0)覆盖。
As others mentioned, to fix it, it's enough to just delete those invalid reference files and re-fetch or re-pull the repository.
正如其他人提到的,要修复它,只需删除那些无效的参考文件并重新获取或重新拉出存储库就足够了。
Example
例子
Error:cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken
错误:cannot lock ref 'refs/remotes/origin/some/branch': unable to resolve reference 'refs/remotes/origin/some/branch': reference broken
Solution:delete the file %repo_root%/.git/refs/remotes/origin/some/branch
解决方法:删除文件%repo_root%/.git/refs/remotes/origin/some/branch
回答by Noel Tock
I had this same issue and solved it by going to the file it was erroring on:
我遇到了同样的问题,并通过转到出错的文件来解决它:
\repo\.git\refs\remotes\origin\master
This file was full of nulls, I replaced it with the latest ref from github.
这个文件充满了空值,我用 github 上的最新引用替换了它。
回答by Uri Shtand
In my case, the problem was solved after I've deleted all the remove reference files under the directory .git
.
就我而言,在删除目录下的所有删除参考文件后,问题解决了.git
。
If you look at the message, it would tell you which files you need to delete (specifically).
如果您查看该消息,它会告诉您需要删除哪些文件(特别是)。
The files to delete sit under .git/refs/remotes
.
要删除的文件位于.git/refs/remotes
.
I've just deleted all the files there, and ran gc prune
我刚刚删除了那里的所有文件,然后运行了 gc prune
git gc --prune=now
After that, everything works just fine.
之后,一切正常。
回答by avivamg
Explanation: It appears your remote repo (in Github / bitbucket) branches were removed ,though your local references were not updated and pointing to non existent references.
说明:看来您的远程仓库(在 Github/bitbucket 中)分支已被删除,尽管您的本地引用未更新并指向不存在的引用。
In order to solve this issue:
为了解决这个问题:
git fetch --prune
git fetch --all
git pull
For extra reading - Reference from Github documentation:
额外阅读 - Github 文档中的参考:
git-fetch- Download objects and refs from another repository
--allFetch all remotes.
--pruneAfter fetching, remove any remote tracking branches which no longer exist on the remote.
git-fetch- 从另一个存储库下载对象和引用
--all获取所有遥控器。
--prune获取后,删除远程上不再存在的任何远程跟踪分支。