Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GIT-无法从远程存储库中删除特定分支_Git - Fatal编程技术网

GIT-无法从远程存储库中删除特定分支

GIT-无法从远程存储库中删除特定分支,git,Git,我无法删除名为origin/featureBranch的远程分支。我猜这是因为分支名称以origin开头,但我不确定: $ git branch -r | grep featureBranch origin/origin/featureBranch $ git push origin :origin/featureBranch error: unable to push to unqualified destination: origin/featureBranch T

我无法删除名为
origin/featureBranch
的远程分支。我猜这是因为分支名称以
origin
开头,但我不确定:

$ git branch -r | grep featureBranch
  origin/origin/featureBranch

$ git push origin :origin/featureBranch

    error: unable to push to unqualified destination: origin/featureBranch

    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:myCompany/my-repo.git'
更新

$git push origin:featureBranch
给出了相同的错误

注意

在远程分支中为
origin/origin/myFeature
,在本地为
origin/myFeature

我知道
origin
通常是什么意思,但就我而言,这是分支名称的一部分

Github没有看到此分支



请任何人解释一下“幕后”发生了什么,以及我如何删除此分支?

只需将
原点
放在冒号后面:

git推送原点:featureBranch

正如Michael解释的,这意味着将“nothing”推送到指定的分支。 这是一个更完整的解释。

这应该可以:

$ git push origin :featureBranch
您已经指定了推送的位置,
来源/
只是本地分支的名称

背景:当git进行抓取时,它会创建所谓的“远程跟踪分支”。 这些分支实际上与您自己的分支没有什么不同,它们只是以远程名称(例如,origin/master)作为前缀,并在本地表示服务器分支(所有提交都已获取)


当您执行推源时,您根本不是指您的本地远程跟踪分支,而是告诉Git“推源sourcebranch:targetbranch”

这条消息表示它找不到任何匹配的分支

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.
如果我尝试删除分支两次,就会得到这样的结果。(第一个成功,第二个失败)。 或者如果分支已被其他人删除。您可以尝试
git remote prune
,看看它是否从
git分支-r
输出中消失。您还可以使用
git ls remote检查分支是否位于
origin
上git@github.com:myCompany/my repo.git

origin
上删除命名奇怪(不好?)的分支,如
origin/master
,对我来说效果很好:

$ git push origin master:origin/master
Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../bare/
 * [new branch]      master -> origin/master

$ git branch -r
  origin/origin/master

$ git push origin :origin/master
To ../bare/
 - [deleted]         origin/master
试试这个:

git push origin :refs/heads/origin/featureBranch
您始终可以在
refs/heads/
下按分支的技术名称引用分支

分支作为小文本文件存储在
.git/refs/
下。本地分支位于
.git/refs/heads/
下,远程分支位于
.git/refs/remotes/
下。因此,可以在
.git/refs/heads/master
.git/refs/remotes/origin/master
找到像
master
这样的简单分支,但您的buggy分支实际上位于
下。git/refs/heads/origin/featureBranch
。它不会与
origin
存储库上的远程分支混淆,因为它不在
refs/remotes/origin/
下,而是在
refs/heads/

在远程服务器上,
origin/featureBranch
分支是服务器的本地分支,因此它将存储在
refs/heads/
下。当推送到一个给定的分支时,您可以通过其名称或路径来识别它,因此如果名称不起作用,只需使用以
refs
开头的完整路径即可


你怎么会得到这个奇怪的分支名称?我不能确定,因为我不知道你做了什么,但我在使用
git push--mirror
时遇到了同样的问题,它推送所有引用,包括远程引用,因此,它将创建一个
origin/branchname
作为本地分支。

请仔细查看我的问题-分支名称从
origin
开始,而不是从远程存储库开始。在remote中,它是
origin/origin/myFeature
哦,很抱歉没有看到。在这种情况下,我只需登录到服务器并在本地删除分支。你可以进入一个简单的克隆回购,然后做git branch-D等等…@MichaelAnderson为我的粗鲁道歉-不想伤害任何人。更改描述:)
您是如何得到这个奇怪的分支名称的?
我正在与许多开发人员一起进行项目。有人创造了这个奇怪的名字,我不知道-谁,如何,为什么:)@thecantotheflat哦,我已经见过六次了。有人想检查origin的
featureBranch
分支,但使用了
git checkout
而不是
git log
,然后可能使用
push发出了
git push
。默认设置他或她不理解。这在新的git用户中是一个非常常见的错误。我通过执行
git push origin myBranch:origin/master
或其他操作意外地创建了这个错误,您的建议解决了我的问题(出于某种原因添加了一个额外的“origin/”)!谢谢。这取决于git版本。我知道它在几个月前曾经失败过,但现在它似乎确实起作用了。我的git是1.7.3.2(不是很新,但也不是很古老),我的1.6.x版本有问题。