38

中央サーバーから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'.

私はgitgc(--prune = nowを使用)を試し、同様のエラーを探しましたが、残念ながら運がありませんでした。

4

6 に答える 6

130

この問題が発生したので、ファイル.git / ORIG_HEADを削除してから、プルを再度実行することで問題を解決しました。.git / ORIG_HEADファイルは、含まれるはずのgit参照ではなく0バイトだったので、削除しました。

于 2013-01-04T15:18:06.333 に答える
10

失敗」「参照を解決できません」「ローカル参照を更新できません」</a>」git remote prune originに加えて、上記の項目を確認してください。git gc --prune=nowgit pull

がある場合は、.git/rebase-mergeそれを削除することを検討してください(「git rebaseおよび削除されたリベースブランチにより、「インタラクティブリベースはすでに開始されています」というエラーメッセージが表示されます」)

この号.git/HEADのように、の内容も確認してください。

これが何らかのリポジトリの破損である場合(「Gitcorrupt master branch」を参照)、最初にリポジトリのクローンを作成し、そのリポジトリの上に現在の変更を再適用してください(git format-patch必要に応じて)

于 2012-05-13T09:39:42.063 に答える
8

この答えは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.

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

rm .git/refs/remotes/origin/BRANCH1

Then git pull, and it should be fine.

于 2016-02-03T05:10:53.183 に答える
3

This file is created when you git pull in a repository in order to not git pull in 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 pull again.

于 2016-11-25T14:46:09.083 に答える
1

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

于 2019-01-25T11:40:29.973 に答える
0

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

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

chown myuser:mygrp .git/ORIG_HEAD
于 2019-03-26T08:32:18.153 に答える