git pull 上的 Git 错误(无法更新本地引用)

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

Git error on git pull (unable to update local ref)

gitcommand-line-interface

提问by user115561

I only have branch master and im getting this error every time i try to "git pull":

我只有分支主并且每次尝试“git pull”时都会收到此错误:

error: Couldn't set refs/remotes/origin/master
From /var/lib/git/xxx/project
 ! a0f80ea..49177a3  master     -> origin/master  (unable to update local ref)

and when i do "git pull origin master" i get:

当我做“git pull origin master”时,我得到:

error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.

i have been searching but cant find why

我一直在寻找,但找不到原因

回答by SkipHyman

My team and I ran into this error, unable to update local ref, when doing a pull in SourceTree.

我和我的团队在拉取 SourceTree 时遇到了这个错误,无法更新本地 ref

We used :

我们用了 :

git gc --prune=now

This removes any duplicate reference objects which should fix the issue.

这将删除任何应该解决问题的重复引用对象。

Here are a few links where you can learn more about git references and pruning:

以下是一些链接,您可以在其中了解有关 git 引用和修剪的更多信息

git tip of the week

本周的 git 提示

git-prune documentation

git-prune 文档

git references

git 引用

回答by Edward Yang

I solved as below:

我解决如下:

git remote prune origin

git remote prune origin

回答by Babak

Try to use this command in your git repository root folder:

尝试在您的 git 存储库根文件夹中使用此命令:

rm .git/logs/refs/remotes/origin/master 

回答by outofBounds

I discoverd the same Error message trying to pull from a Bitbuck Repo into my lokal copy. There is also only one Branche Master and the command git pull origin masterlead to this Error Message

我在尝试从 Bitbuck Repo 中提取到我的本地副本时发现了相同的错误消息。也只有一个 Branche Master 并且该命令git pull origin master会导致此错误消息

From https://bitbucket.org/xxx
 * branch            master     -> FETCH_HEAD
error: Couldn't set ORIG_HEAD
fatal: Cannot update the ref 'ORIG_HEAD'.

Solution as follows

解决方法如下

  1. git reflogfind the number of the last commit
  2. git reset --hard <numnber>reset to the last commit
  3. git pull origin masterpull again without error
  1. git reflog找到最后一次提交的编号
  2. git reset --hard <numnber>重置为最后一次提交
  3. git pull origin master再次拉,没有错误

回答by Xin

rm .git/refs/remotes/origin/master

rm .git/refs/remotes/origin/master

It works to me!

它对我有用!

回答by tpg2114

Ensure the user that is executing the git pullis the same user that created the repository. The file permissions are incorrect.

确保执行 的git pull用户与创建存储库的用户相同。文件权限不正确。

回答by T.Moez

with gitbach line commande, use git update-refto update reference of your local branch:

使用 gitbach line commande,用于git update-ref更新本地分支的引用:

$ git update-ref -d refs/remotes/origin/[locked branch name]

then pull using $ git pull

然后拉使用 $ git pull

[locked branch name]is the name of the branch that the error is happening because of mismatch of commit Ids.

[locked branch name]是由于提交 ID 不匹配而发生错误的分支的名称。

回答by daGUY

This is probably a very niche situation, but: I run Windows in a Parallels VM on my MacBook Pro, with my local repos stored on the VM's disk, which is shared with macOS.

这可能是一个非常小众的情况,但是:我在 MacBook Pro 上的 Parallels VM 中运行 Windows,我的本地存储库存储在 VM 的磁盘上,该磁盘与 macOS 共享。

If I have a file open in a Mac app from a repo that's located on the Windows VM, I sometimes get the "unable to update local ref" error. The solution when this happens is to simply close the file or quit the Mac app.

如果我从位于 Windows VM 上的存储库在 Mac 应用程序中打开一个文件,我有时会收到“无法更新本地引用”错误。发生这种情况时的解决方案是简单地关闭文件或退出 Mac 应用程序。

回答by Hazok

This error with (unable to update local ref) can also happen if you have changed passwords recently and there's some fancy stuff integrating your Windows and Linux logins.

如果您最近更改了密码并且有一些花哨的东西集成了您的 Windows 和 Linux 登录,也会发生此错误(无法更新本地引用)。

回答by Gabriel Santos Carvalho

Clone the repository again, and copy the .git folder in your broken project.

再次克隆存储库,并复制损坏项目中的 .git 文件夹。