为什么 git 拉取失败?

Why git pull fails?

今天,假设我遇到了 git 问题。我使用 git (仅 pushpull 命令) 已经 1 年了,到目前为止一切都很好。但是今天这个命令不起作用并抛出错误:

$ git pull origin master

这是错误:

有人知道问题出在哪里吗?我该如何解决?

检查.git\refs\remotes\origin

中是否有主文件

如果这样做,请将其删除,然后再试一次 git pull

作为替代方案,只需尝试在另一个文件夹中再次克隆您的存储库,看看错误是否仍然存在。

作为torek mentions

the string "reference broken" means that the indicated ref name exists, it just has an invalid SHA-1 hash ID attached to it.
That's not supposed to happen (the ref name itself should have been destroyed by now), so it's not clear how this came about.

您可以在refs/files-backend.c#lock_raw_ref()

中看到错误信息
if (errno == EINVAL && (*type & REF_ISBROKEN)) {
            strbuf_addf(err, "unable to resolve reference '%s': "
"reference broken", refname);

该检查是在 Git 2.10 (April 2016) 中引入的,其中提到:

This makes use of a new function, lock_raw_ref(), which is analogous to read_raw_ref(), but acquires a lock on the reference before reading it.

This change still has two problems:

  • There are redundant read_ref_full() reference lookups.
  • It is still possible to get incorrect reflogs for symbolic references if there is a concurrent update by another process, since the old_oid of a symref is determined before the lock on the pointed-to ref is held.

在解决了相同错误的 Whosebug 上检查这个问题:

Git and nasty "error: cannot lock existing info/refs fatal"

引用已接受的答案:

This happened to me when my git remote (bitbucket.org) changed their IP address. The quick fix was to remove and re-add the remote, then everything worked as expected. If you're not familiar with how to remove and re-add a remote in git, here are the steps: Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:

git remote -v

which will print out something like this:

origin git@server-address.org:account-name/repo-name.git (fetch)
origin git@server-address.org:account-name/repo-name.git (push)

Remove the remote from your local git repo:

git remote rm origin

Add the remote back to your local repo:

git remote add origin git@server-address.org:account-name/repo-name.git