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

    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 push origin :refs/heads/origin/featureBranch

您始终可以通过 refs/heads/ 下的技术名称引用分支.

一个分支被存储为.git/refs/下的一个小文本文件。 .本地分支机构下.git/refs/heads/.git/refs/remotes/<remotename>/ 下的远程分支机构.一个简单的分支,如 master因此可以在 .git/refs/heads/master 找到和 .git/refs/remotes/origin/master ,但您的 buggy 分支实际上位于 .git/refs/heads/origin/featureBranch 下.它不会与 origin 上的远程分支混淆存储库,因为它不在 refs/remotes/origin/ 下, 但在 refs/heads/ 下.

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

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

关于GIT - 无法从远程存储库中删除特定分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192676/

相关文章:

git - 如何配置 maven-release-plugin 以使用 maven-scm-provider-gitexe 'shallow' 选项

git - 我如何要求(或敦促)git 提交者提供相关的作者信息?

eclipse - 如何使用 EGIT 将现有的 Eclipse 项目推送到 Bitbucket?

git - 如何卸载 git-for-windows 并在新位置重新安装?

SVN 到 Git 导入问题使用 "git svn clone"

检测到 Git 大文件

windows - 如何在 Windows 的 Git Credential Manager 中按存储库在本地存储凭据?

安卓工作室错误 : Configuration with name 'default' not found

git - 为什么 git-cherry pick 什么都不说?

git - 为什么 git 忽略我更改的文件?