如何删除一个名为' -delete'的分支?

发布于 2025-01-18 02:31:50 字数 280 浏览 5 评论 0原文

我意外地创建了一个名为-delete的本地分支

当我尝试运行命令以使用它删除分支的命令时,

git branch -d -delete

git branch -D -delete

git branch --delete -delete

,并给出了错误的消息,说:

error: did you mean `--delete` (with two dashes ?)

如何删除“ -delete”分支?

I have accidentally created a local branch called -delete

When I try to run commands to delete the branch using

git branch -d -delete

git branch -D -delete

git branch --delete -delete

It does not work and gives the error message back that says this:

error: did you mean `--delete` (with two dashes ?)

How can I delete the '-delete' branch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海未深 2025-01-25 02:31:50

git分支还要尊敬-章节:如果您通过-单独作为命令行上的参数,那么此后的任何内容都不会是被解释为一种选择。

从 @torek在

$ git branch delete && mv .git/refs/heads/delete .git/refs/heads/-delete
$ git branch
  -delete
* master

$ git branch -d -delete     # fails
error: did you mean `--delete` (with two dashes)?

$ git branch -d -- -delete  # works
Deleted branch -delete (was cec927c).

$ git branch
* master

git branch also honors the -- convention : if you pass -- alone as an argument on the command line, anything after that will not be interpreted as an option.

Starting from @torek's setup in his answer :

$ git branch delete && mv .git/refs/heads/delete .git/refs/heads/-delete
$ git branch
  -delete
* master

$ git branch -d -delete     # fails
error: did you mean `--delete` (with two dashes)?

$ git branch -d -- -delete  # works
Deleted branch -delete (was cec927c).

$ git branch
* master
回眸一遍 2025-01-25 02:31:50

没有以用户为导向的git命令让您首先让您创建该分支名称(我不得不求助于骗子来自己设置条件,因为我不认为使用> git update-ref立即),但是一旦拥有,摆脱错误名称的方法是使用git git update-ref

git update-ref -d refs/heads/-delete

这是我的示例:

$ git branch delete
$ mv .git/refs/heads/delete .git/refs/heads/-delete
$ git branch
  -delete
  diff-merge-base
* master
$ git branch -d -delete
error: did you mean `--delete` (with two dashes)?
$ git update-ref -d refs/heads/-delete
$ git branch
  diff-merge-base
* master

No user-oriented Git command should have let you create that branch name in the first place (I had to resort to trickery to set up the condition myself, as I didn't think to use git update-ref right off), but once you have it, the way to get rid of the bad name is to use git update-ref:

git update-ref -d refs/heads/-delete

Here's my example:

$ git branch delete
$ mv .git/refs/heads/delete .git/refs/heads/-delete
$ git branch
  -delete
  diff-merge-base
* master
$ git branch -d -delete
error: did you mean `--delete` (with two dashes)?
$ git update-ref -d refs/heads/-delete
$ git branch
  diff-merge-base
* master
再见回来 2025-01-25 02:31:50

我遇到了同样的问题。我发现的唯一方法是通过git gui删除它。

1-右键单击您的项目目录,然后在此处单击GIT GUI
2-从Navbar单击分支,然后单击删除
3-从本地分支框和下面的第二个框中选择分支,然后单击

完成的 删除
在此处输入图像描述

I had the same problem. The only way that I found was to delete it by git GUI.

1- Right click in your project directory and then click on git GUI here
2- From the navbar click on branch then click on delete
3- choose the branch from the local branches box and the second box below, then click on the delete

Done
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文