git push commit显示错误:无法推送到不合格的目的地

时间:2018-01-23 17:59:59

标签: bash git

我试图通过WIP显示错误(例如

)将头部提交推送到远程
$ git push remote 51447424149c671958a2f76ec1fefb135a5c2cea:WIP-51447424149c671958a2f76ec1fefb135a5c2cea

[导致]

error: unable to push to unqualified destination: WIP-51447424149c671958a2f76ec1fefb135a5c2cea
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'https://github.com/abc'

任何帮助?

2 个答案:

答案 0 :(得分:5)

TL; DR

你可能想要:

$ git push remote 51447424149c671958a2f76ec1fefb135a5c2cea:refs/heads/WIP-51447424149c671958a2f76ec1fefb135a5c2cea

创建名为WIP-51447424149c671958a2f76ec1fefb135a5c2cea的分支。 (确保你真的想要创建这个名字,因为它有点不合适。它的有效并且它没有任何问题,它只是一个哎呀输入的东西。)

Git抱怨的是需要一些解释:

  • 分支名称是引用的特殊形式
  • 引用是以refs/开头的字符串。熟悉的两种引用是分支名称和标记。 (稍后会详细介绍这一点。)
  • 参考文献可以缩写......有时,但并非总是如此。
  • 有时候(对Git有意义的地方)你可以使用原始哈希ID而不是引用。
  • git push采用 refspec ,这是一对以冒号分隔的引用(并且可选地,整个事物可以加上前缀)。

您使用git push正在使用(非常长的)refspec 51447424149c671958a2f76ec1fefb135a5c2cea:WIP-51447424149c671958a2f76ec1fefb135a5c2cea。此refspec的左侧是引用,右侧是目标引用。

结肠左侧的东西显然是 1 一个哈希ID。因此,这是利用特殊情况,您可以提供哈希ID而不是实际引用(只要该对象实际存在于您的Git存储库中)。

冒号右侧的东西是名称,而不是哈希ID。这很好,因为这是Git 需要名称的地方之一。但这也是一个问题,因为名称WIP-something并非以refs/开头。

请注意,Git明确抱怨:

  

目的地......也不以refs/

开头

在我们完成剩下的工作之前,让我们再次提及分支和标签。像master这样的分支名称是参考refs/heads/master的简称。像v1.2这样的标记名称是参考refs/tags/v1.2的简写。请注意,在这两种情况下,这些都以refs/开头。他们继续说出我们正在使用的种类

  • 分支名称引用以refs/heads/开头。
  • 标记名称引用以refs/tags/开头。

换句话说,当我们说分支和标签是引用的形式时,我们说的是给定引用,你可以看看refs/之后的内容。并找出它的种类refs/heads/表示"分支"并且refs/tags/表示"标记"。 (如果您看到refs/remotes/,则表示它是远程跟踪名称;并且refs/之后还有更多特殊字词,例如{{1} } notes/。)

我们上面也说过,引用可以有时缩写。这是Git在这里抱怨的第一部分,但是:

  

...既不匹配遥控器上现有的参考...

你被允许遗漏git notes部分,并拥有另一个Git - 你的Git推送的那个 - 弄明白 {{1} }真的意味着refs/heads/。但这仅在他们已经拥有master时才有效。如果您正在尝试创建分支,则必须告诉其他Git:我希望您创建一个新分支。

您可以通过提供引用的全名来执行此操作:例如refs/heads/master。以refs/heads/master开头的事实告诉其他Git:我想创建一个分支名称。如果你发送它们{{1}你告诉他们要创建一个新的标签名称。

无论如何,这就是为什么你得到了相当长的抱怨,其中包括两部分:"既不是......也不是"。因此,解决方案是向他们发送全名。

1 什么,不是很明显吗? :-)这让我想起那些通过六次转换证明定理的教授然后说"其余的是显而易见的......"。

答案 1 :(得分:0)

Git 2.21(2019年第一季度,一年后)将改善该错误消息:当git push $there $src:$dst不是完全合格的refname并且不清楚最终用户的含义时,“ $dst”将拒绝。

已指导代码路径给出更清晰的错误消息,并通过考虑所推送对象的类型(例如,标记对象希望进入refs/tags/下)来猜测应该往哪里推送。

注意:DWIM (used below) is "do what I mean"

  

计算机系统试图预测用户的意图,自动纠正一些小错误,而不是盲目地执行用户的显式但可能不正确的输入。

请参见commit 2219c09commit bf70636commit dd8dd30commit 04d1728commit c83cca3commit 8b0e542commit cab5398(2018年11月13日)由Ævar Arnfjörð Bjarmason (avar)
(由Junio C Hamano -- gitster --commit 0a84724中合并,2019年1月4日)

  

push:改进了不合格的<dst>推送中显示的错误

     

改进在f8aae12中添加的错误消息(“ push:允许   DWIM的非标准dest refspecs”,2008-04-23,Git v1.5.5.2),在此之前   变化看起来像这样:

$ git push avar v2.19.0^{commit}:newbranch -n
error: unable to push to unqualified destination: newbranch
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'git@github.com:avar/git.git'
     

需要非常仔细地阅读此消息,以发现如何纠正错误,即,推送至refs/heads/newbranch

     

现在,消息看起来像这样:

$ ./git-push avar v2.19.0^{commit}:newbranch -n

error: The destination you provided is not a full refname (i.e.,
starting with "refs/"). We tried to guess what you meant by:

- Looking for a ref that matches 'newbranch' on the remote side.
- Checking if the <src> being pushed ('v2.19.0^{commit}')
  is a ref in "refs/{heads,tags}/". If so we add a corresponding
  refs/{heads,tags}/ prefix on the remote side.

Neither worked, so we gave up. You must fully qualify the ref.
error: failed to push some refs to 'git@github.com:avar/git.git'
     

此改进是线程“ Re:[PATCH 2/2] push:对不合格的<dst> pushcomment #1(十月2018)和comment #2,以及我自己的修复程序/重新格式化/措辞放在顶部。

     

Jeff在名单上的建议是提出第二个要点“ Looking at the refname of the local source.”。
  此处添加的版本更详细,但也更准确。
  说“本地源”可以引用本地引用存储中的任何引用,包括refs/remotes/*中的内容。以后的更改将指导guess_ref()推断引用   从远程引用引用中键入内容,所以不要混淆两者。

这还不是全部:现在有一个新设置。

  

现在使用 advice.pushUnqualifiedRefName=true (默认情况下处于启用状态)显示   有关如何进行操作的提示:

$ ./git-push avar v2.19.0^{commit}:newbranch -n

error: The destination you provided is not a full refname (i.e.,
starting with "refs/"). We tried to guess what you meant by:

- Looking for a ref that matches 'newbranch' on the remote side.
- Checking if the <src> being pushed ('v2.19.0^{commit}')
  is a ref in "refs/{heads,tags}/". If so we add a corresponding
  refs/{heads,tags}/ prefix on the remote side.

Neither worked, so we gave up. You must fully qualify the ref.
hint: The <src> part of the refspec is a commit object.
hint: Did you mean to create a new branch by pushing to
hint: 'v2.19.0^{commit}:refs/heads/newbranch'?
error: failed to push some refs to 'git@github.com:avar/git.git'
     

在尝试推送标签,树或Blob时,我们建议用户可能打算将其推送到refs/tags/

config has a new advice

  

pushUnqualifiedRefname:

     

git push放弃尝试根据源和目标ref进行猜测时显示,但是源仍然可以建议用户将其推送到refs/heads/*或{ {1}}基于源对象的类型。