git pull 错误:错误:远程参考在但预期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11796580/
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 error :error: remote ref is at but expected
提问by Sanjeev Kumar Dangi
Full message:
完整信息:
error: Ref refs/remotes/origin/user is at 3636498c2ea7735fdcedc9af5ab3c8689e6abe77 but expected a21359c6cc2097c85775cde6a40105f4bd7100ec
From github.com:{github project url}
! a21359c..6273ffc user -> origin/user (unable to update local ref)
回答by krijesta
If you are running git under a file system that is not case sensitive (Windows or OS X) this will occur if there are two branches with the same name but different capitalisation, e.g. user_model_changes
and User_model_changes
as both of the remote branches will match the same tracking ref.
如果您在不区分大小写的文件系统(Windows 或 OS X)下运行 git,如果有两个名称相同但大小写不同的分支,则会发生这种情况,例如user_model_changes
,User_model_changes
两个远程分支将匹配相同的跟踪引用.
Delete the wrong remote branch (you shouldn't have branches that differ only by case) and then git remote prune origin
and everything should work
删除错误的远程分支(您不应该拥有仅因大小写而异的分支),然后git remote prune origin
一切正常
回答by JDiMatteo
Permanent Fix
永久修复
git update-ref -d
resolved my instance of this error, e.g.
git update-ref -d
解决了我的这个错误实例,例如
git update-ref -d refs/remotes/origin/user
Note that this doesn't impact remote.
请注意,这不会影响远程。
In my case, a subsequent git fetch
fetched that branch again, and following git fetches/pulls no longer gave the error "remote ref is at but expected".
在我的情况下,随后git fetch
再次获取该分支,并且在 git fetches/pulls 之后不再给出错误“remote ref is at but expected”。
If that doesn't work, a temporary fix:
如果这不起作用,请临时修复:
Note also that if you don't care about the branch in question (e.g. you just want to update master, not origin/user), a git pull
workaround is to fetch then just merge the particular branch you care about, e.g.
另请注意,如果您不关心有问题的分支(例如,您只想更新 master,而不是 origin/user),则git pull
解决方法是获取然后合并您关心的特定分支,例如
git fetch # may give an error for a particular branch, but other branches will still be successfully fetched
git merge origin/master
回答by Prakash Saravanan
Just delete the folders and files under \.git\refs\remotes\origin
.
Works, when u don't have unpushed changes.
只需删除\.git\refs\remotes\origin
. 有效,当您没有未推送的更改时。
回答by elad silver
I ran this to solve the problem:
我运行这个来解决问题:
git gc --prune=now
回答by Narender Gusain
Use the below two commands one by one.
一一使用以下两个命令。
git gc --prune=now
git remote prune origin
This will resolve your issue.
这将解决您的问题。
回答by jogam5
I had to remove my branchfrom my command line at:
我不得不从我的命令行中删除我的分支:
.git\refs\remotes\{my remote}\{**my branch**}
and then manually doing:
然后手动执行:
git pull [remote_name] [branch_name]
I was able to pull the changes.
我能够进行更改。
Note: I was using SourceTreeand was unable to do the pull.
注意:我使用的是SourceTree并且无法进行拉取。
回答by mruanova
A hard reset will also resolve the problem
硬重置也将解决问题
git reset --hard origin/master
回答by shareef
Clearer Steps
更清晰的步骤
in terminal
cd /.git/refs/remotes/origin
do
ls
, you will see some branchesand HEADRemove the branch you think has the problem
rm branchname
If it did not work, delete all branches/HEAD
- you may wana pull
在终端
cd /.git/refs/remotes/origin
做
ls
,你会看到一些分支和HEAD删除您认为有问题的分支
rm branchname
如果它不起作用,请删除所有分支/HEAD
- 你可能想拉
Hope it works now.
希望它现在有效。
回答by Andrei S.
Unfortunately GIT commands like prune and reset or push didn't work for me. Prune worked once and then the issue returned.
不幸的是,像 prune 和 reset 或 push 这样的 GIT 命令对我不起作用。修剪工作一次,然后问题又回来了。
The permanent solution which worked for me is to edit a git file manually. Just go to the project's .git folder and then open the file packed-refs in a text editor like Notepad++. Then navigate to the row with the failing branch and update its guid to the expected one.
对我有用的永久解决方案是手动编辑 git 文件。只需转到项目的 .git 文件夹,然后在 Notepad++ 之类的文本编辑器中打开文件packed-refs。然后导航到失败分支的行并将其 guid 更新为预期的。
If you have a message like:
如果你有这样的消息:
"error: cannot lock ref 'refs/remotes/origin/feature/branch_xxx': is at 425ea23facf96f51f412441f41ad488fc098cf23 but expected 383de86fed394ff1a1aeefc4a522d886adcecd79"
“错误:无法锁定 ref 'refs/remotes/origin/feature/branch_xxx':位于 425ea23facf96f51f412441f41ad488fc098cf23 但预期为 383de86fed394ff1a1aeefc4a522d7986”
then in the file find the row with 'refs/remotes/origin/feature/branch_xxx'. The guid there will be the expected (2nd) one - 383de86fed394ff1a1aeefc4a522d886adcecd79. You need to change it to the real (1st) one - 425ea23facf96f51f412441f41ad488fc098cf23.
然后在文件中找到带有“refs/remotes/origin/feature/branch_xxx”的行。那里的 guid 将是预期的(第二个)- 383de86fed394ff1a1aeefc4a522d886adcecd79。您需要将其更改为真正的(第一个) - 425ea23facf96f51f412441f41ad488fc098cf23。
Repeat for the other failing branches and you'll be good to proceed. Sometimes after re-fetch I had to repeat for the same branches which i already 'fixed' earlier. On re-fetch GIT updates guids and gives you the latest one.
重复其他失败的分支,你会很高兴继续。有时在重新获取后,我不得不重复我之前已经“修复”的相同分支。在重新获取 GIT 更新 guids 并为您提供最新的。
Anyways the issue isn't a show stopper. The branch list gets updated. This is rather a warning.
无论如何,问题不是表演障碍。分支列表得到更新。这倒是一个警告。
回答by Ranganatha G V
Try this, it worked for me.
In your terminal: git remote prune origin
.
试试这个,它对我有用。在你的终端:git remote prune origin
。