git 删除名称包含特殊字符的分支

问题描述 投票:0回答:4

你能帮我一下吗? 我创建了一个名称错误的 git 分支,但无法删除它,因为该名称包含一些疯狂的字符。我复制并粘贴了名字,不幸的是在文本末尾有一些看不见的字符。

>git ls-remote
5fe385e6bd6b49f87f470e0a5b22b67042b179ad        HEAD
dbdadb9d8c630782144028d50f01b84a6ff61612        refs/heads/feature/ABC-495-test1
6660c993b5a5e35922a1f7b3f2bb75c6b0996f6e        refs/heads/feature/ABC-496
dbdadb9d8c630782144028d50f01b84a6ff61612        refs/heads/feature/ABC-501-mapping
dbdadb9d8c630782144028d50f01b84a6ff61612        refs/heads/feature/ABC-501-mapping?
5fe385e6bd6b49f87f470e0a5b22b67042b179ad        refs/heads/master

我想删除名称为“refs/heads/feature/ABC-501-mapping?”的分支,但我不知道如何:(

谢谢

git branch special-characters
4个回答
8
投票

试试这个:

$ git checkout master
$ git branch -D "feature\/ABC-501-mapping\?"         # delete local branch
$ git push origin :"feature\/ABC-501-mapping\?"      # delete remote branch

或者,

$ cd .git/refs/heads
$ rm "feature/ABC-501-mapping?"

1
投票

当我无法输入特殊字符时,我找到了一种通过将分支名称通过管道传递到删除命令来删除远程分支的方法:

git ls-remote|grep -i <partial name of the branch>|cut -f3 -d/|tail -1|xargs git push origin -d

0
投票

与 Yair 类似的选项。

我很幸运通过 gitbranch --all 命令将整个分支名称(远程前缀和所有)复制出 git bash 窗口(注意:对我来说至少我没有在 bash 中看到特殊字符),然后粘贴它进入删除,然后从分支名称中删除远程前缀(从左侧开始,以免删除任何特殊字符,如果它们碰巧是第一个)。

您可以选择使用 grep 来缩小分支命令的范围

git branch --all | grep <string to match branch>
git push origin --delete <copy pasted branch with deleted remote prefix>

0
投票

我的特殊分支名称:60954_Plante_transient_60_pack_raf_odessa_r992�_fin

我的抑制分支的命令

git 分支 --全部 | grep 60954_Plante_transie | grep 60954_Plante_transie | xargs git 分支 -D

删除分支 60954_Plante_transient_60_pack_raf_odessa_r992�_fin(原为 d6bfec3)。

© www.soinside.com 2019 - 2024. All rights reserved.