git branch -d <branchname> throws error: branch <branchname> not found

git branch -d <branchname> throws error: branch <branchname> not found

当我输入 git branch 时,我得到

* master
localbranch

但是当我尝试删除分支 git branch -d localbranch 时,出现未找到错误:

error: branch 'localbranch' not found.

我也试过用git branch -D localbranch强制删除,但它给了我同样的错误。

分支已损坏,我执行了以下步骤 Git repository corrupt (incorrect header check; loose object is corrupt) 来删除损坏的文件。但是现在我无法删除该分支。

分支存储为包含它们指向的 SHA 的文件。尝试从项目中的 .git/refs/head/ 目录中删除此分支的名为 localbranch 的文件:

rm .git/refs/heads/localbranch

在某些情况下,分支包含终端中不显示的字符window,所以我需要直接转到存储库。

我的 Git Windows 最终处于这种状态:

$ git branch -l
  master
* next
  my-topic-branch

但是移除失败

$ git branch -D my-topic-branch
error: branch 'my-topic-branch' not found.

显示 heads 目录的内容显示分支名称更复杂...

$ ls -al .git/refs/heads
total 7
drwxr-xr-x 1 112802 197121  0 Oct 11 13:06 ./
drwxr-xr-x 1 112802 197121  0 Jul 11 14:30 ../
-rw-r--r-- 1 112802 197121 41 Oct  4 12:39 ''$'22''my-topic-branch'
-rw-r--r-- 1 112802 197121 41 Sep 15 15:23 master
-rw-r--r-- 1 112802 197121 41 Oct 11 13:05 next
drwxr-xr-x 1 112802 197121  0 Jul 12 13:28 origin/

而且我可以成功删除全名

$ git branch -D ''$'22''my-topic-branch'
Deleted branch my-topic-branch (was efbc2fa).