无法拉取,git 无法解析引用 ORIG_HEAD

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10570319/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:40:49  来源:igfitidea点击:

Cannot pull, git cannot resolve reference ORIG_HEAD

git

提问by vvondra

while pulling into my git repository from our central server, this error occured:

从我们的中央服务器拉入我的 git 存储库时,发生了此错误:

$ git pull origin master

From http://aaa/repo
 * branch            master     -> FETCH_HEAD
error: unable to resolve reference ORIG_HEAD: No such file or directory
fatal: Cannot lock the ref 'ORIG_HEAD'.

I've tried git gc (with --prune=now) and looking for a similar error, unfortunately with no luck.

我试过 git gc (使用 --prune=now)并寻找类似的错误,不幸的是没有运气。

回答by Brian Minton

I had this problem, and I solved it by removing the file .git/ORIG_HEAD then doing the pull again. The .git/ORIG_HEAD file was 0 bytes instead of the git reference it was supposed to contain, so I just got rid of it.

我遇到了这个问题,我通过删除文件 .git/ORIG_HEAD 然后再次拉动来解决它。.git/ORIG_HEAD 文件是 0 字节,而不是它应该包含的 git 引用,所以我只是摆脱了它。

回答by VonC

Check the git remote prune originmentioned in addition of the git gc --prune=nowin "git pullfails “unalble to resolve reference” “unable to update local ref”".

检查“失败“无法解析引用”“无法更新本地引用”中git remote prune origin提到的附加项。git gc --prune=nowgit pull

If you have a .git/rebase-merge, consider removing it (as in "git rebaseand deleted rebasing branches causing “Interactive rebase already started” error message")

如果您有.git/rebase-merge,请考虑将其删除(如“git rebase并删除变基分支导致“交互式变基已经启动”错误消息“)

Check also the content of .git/HEAD, as in this issue.

还检查内容.git/HEAD,如本期

If this is a repo corruption of some kind (see "Git corrupt master branch"), try first to clone your repo again, and re-apply your current modifications on top of that repo (through git format-patchif you need to)

如果这是某种存储库损坏(请参阅“ Git 损坏的主分支”),请先尝试再次克隆您的存储库,然后在该存储库之上重新应用您当前的修改(git format-patch如果需要,则通过)

回答by Ariel Cabib

This answer doesn't solve the OP's problem, but solves a similar one.

这个答案并没有解决 OP 的问题,而是解决了一个类似的问题。

I had a similar problem (I got error: cannot lock ref ... is at ... but expected ...), but it was because there were two branches in the repo with the same name, but with different case. Maybe this answer could help people that get here, I wasn't able to find an answer elsewhere. I deleted one of the branches, and then deleted its corresponding reference from: .git/ref/.../branch_name, then git pulled. This happens due to me working on a case-insensitive file system, while the two branches were pushed on a case-sensitive file system.

我有一个类似的问题(我得到了error: cannot lock ref ... is at ... but expected ...),但这是因为 repo 中有两个具有相同名称但大小写不同的分支。也许这个答案可以帮助到这里的人,我无法在其他地方找到答案。我删除了其中一个分支,然后删除了它对应的引用 from: .git/ref/.../branch_name,然后 git pull 。发生这种情况是因为我在一个不区分大小写的文件系统上工作,而这两个分支是在区分大小写的文件系统上推送的。

For example, the two branches are BRANCH1and branch1, and they are both under originremote. First, delete one of the branches, for example BRANCH1. Then remove its ref:

比如两个分支是BRANCH1branch1,都在originremote下。首先,删除其中一个分支,例如BRANCH1。然后删除它的引用:

rm .git/refs/remotes/origin/BRANCH1

Then git pull, and it should be fine.

然后git pull,应该没问题。

回答by Romulus

This file is created when you git pullin a repository in order to not git pullin the same repository more then ones at the time and it gets deleted when the process is finished. If the process dies or become a zombie, then the file is not removed and you have to check manually if the git process still exists. If the process doesn't exists, then you have to delete the file and try to git pullagain.

当您git pull在存储库中时创建此文件,以便git pull当时不在同一个存储库中,并且在该过程完成后将被删除。如果进程死掉或变成僵尸,那么文件不会被删除,你必须手动检查 git 进程是否仍然存在。如果该进程不存在,则您必须删除该文件并重试git pull

回答by Gallaecio

I had to remove .git/ORIG_HEAD.lock, not (just) .git/ORIG_HEAD.

我必须删除.git/ORIG_HEAD.lock,而不是(只是).git/ORIG_HEAD

回答by gaborsch

I had Unix permission issues, I used the same git repo with two different users (one was root, the other was my private user).

我有 Unix 权限问题,我对两个不同的用户使用了相同的 git repo(一个是root,另一个是我的私人用户)。

So, I had to change the file ownership on .git/ORIG_HEADto my personal user, that resolved the issue.

因此,我不得不将文件所有权更改.git/ORIG_HEAD为我的个人用户,从而解决了问题。

chown myuser:mygrp .git/ORIG_HEAD