推送时出现 Git 错误 - update_ref 失败 [英] Git error when pushing - update_ref failed

查看:34
本文介绍了推送时出现 Git 错误 - update_ref 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试推送本地提交时遇到问题,这可能是在 Android Studio 崩溃时发生的.这是错误:

I have a problem when i try to push my local commits, it has probably happened when Android Studio has crushed. Here is the error:

ref 'refs/remotes/origin/master' 的 update_ref 失败:无法锁定ref 'refs/remotes/origin/master': 无法解析引用refs/remotes/origin/master: 无效参数

update_ref failed for ref 'refs/remotes/origin/master': cannot lock ref 'refs/remotes/origin/master': unable to resolve reference refs/remotes/origin/master: Invalid argument

$git stash 表示 HEAD 现在是我的最新提交.

$git stash says that HEAD is now at my latest commit.

我仍然是 git 的初学者,我不知道如何解决它.. 我该怎么办?

I'm still a beginner in git and I have no idea how to fix it.. What can I do?

推荐答案

您的 refs/remotes/origin 目录(这是您本地存储库中的一个目录)存在某种问题.(我不清楚到底出了什么问题,但你猜测它发生在 Android Studio 崩溃时似乎对我来说也很可能.)

Your refs/remotes/origin directory—this is a directory within in your local repository—has some sort of problem. (It's not clear to me what exactly went wrong, but your guess that it happened when Android Studio crashed seems likely to me as well.)

要修复它,您可以可能使用以下命令序列.请注意,我一般不推荐它——您的 Git 服务,无论是 Android Studio 还是普通的命令行 Git,都不应该崩溃并留下损坏的存储库,因此您永远不应该> 要做到这一点,这只是紧急维修,例如在树木倒下后将胶带粘在您的汽车上1,足以让您稍后进行适当的维修/更换车辆:

To fix it, you can probably use the sequence of commands below. Note that I don't recommend it in general—your Git service, whether that's Android Studio or ordinary command-line Git, is not supposed to crash and leave you with a broken repository, so you should never have to do this, it's just an emergency repair, something like putting duct tape all over your car1 after a tree fell on it, just enough to get you to a proper repair / replacement vehicle later:

$ cd $(git rev-parse --show-toplevel)  # if necessary
$ rm -rf .git/refs/remotes/origin      # remove all origin/*
$ mkdir .git/refs/remotes/origin       # create empty origin/
$ git fetch origin                     # repopulate origin/*

在任何情况下,您的 git push 很可能此时实际上已经成功,因为失败的是对您的 origin/master 远程跟踪分支的更新.

In any case it's likely that your git push has actually succeeded at this point, since what is failing is the update to your origin/master remote-tracking branch.

您的 Git 刚刚完成与 origin 上的另一个 Git 的对话,为他们(origin 的用户)提供了他们的 master 更新,并且origin 已经接受了这些更新,并且您的 Git 现在正在记录一个事实,即上次它与 origin他们的 master 交谈 被设置为某个特定的提交哈希——你刚刚推送的那个.

Your Git has just finished talking to another Git on origin, giving them (the users of origin) updates for their master, and origin has accepted those updates, and your Git is now recording the fact that, the last time it talked with origin, their master was set to some particular commit hash—the one you just pushed.

(请记住,您的 origin/* 远程跟踪分支只是为您记录 Git 看到的他们的 Git 在其分支中的内容.您的 Git 更新这些当你运行 git fetch 时,你的 Git 与他们的 Git 对话并获取它的所有分支.当你的Git 与他们的 Git 对话并要求他们设置一个或多个分支,以您的 Git 提供给他们的哈希值.)

(Remember that your origin/* remote-tracking branches are just recording, for you, what your Git saw that their Git has for its branches. Your Git updates these when you run git fetch, where your Git talks to their Git and gets all of its branches. Your git also updates some—not all—on git push, when your Git talks to their Git and asks them to set one or more branches, to the hashes your Git hands them.)

1除了作为 Git 技工,我推荐的部件实际上是适当的车身面板、皮带和软管以及夹子,而不仅仅是胶带、打包线和口香糖.:-)

1Except that as a Git mechanic, instead of just duct tape, baling wire, and chewing gum, my recommended parts are actually proper body panels, belts and hoses, and clamps. :-)

这篇关于推送时出现 Git 错误 - update_ref 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆