用任何名称而不是名称删除git branch [英] Delete git branch by anything, not name
问题描述
我在删除git分支时遇到问题.最初,我能够使用'git checkout -b ....'创建它.但是在我看来,我在书写时犯了一个错误,遇到了错误,然后退格了.导致该分支的名称错误.
I have a problem with deleting git branch. At first I was able to create it using 'git checkout -b ....'. But it seems to me, that I made a mistake while writing, hit something wrong, then backspace. It resulted in wrong name of this branch.
我能够在这个分支上工作,甚至可以将其推送到远程,但它的行为很奇怪(无法在Web界面中看到分支).
I was able to work on this branch, even push it to remote, but it makes weird behavior (cannot see branches in web interface).
git branch -r显示了我
git branch -r shows me
origin/master
origin/rrseria_test_utility
在Web界面(bitbucket)中,我可以在具有以下名称的提交中看到此分支
In web interface (bitbucket) I can see this branch in commits with following name
rrseriaÅl_test_utility
Pleasse请注意,大写字母A不仅是A,而且是圆圈上方的A.好像是utf-8字符"U + 00C5".
Pleasse note that capital A is not just A, but A with circle above. Seems like utf-8 character 'U+00C5'.
当我尝试将其删除时,
git branch -d rrseria_test_utility
error: branch 'rrseria_test_utility' not found.
git checkout rrseria_test_utility
error: pathspec 'rrseria_test_utility' did not match any file(s) known to git.
您能帮我如何删除该分支吗?
Can you help me how to delete this branch ?
推荐答案
您可以使用 git branch --list rrseria*
仅列出名称以rrseria
开头的分支.如果有多个,则可以使用更特定的模式,对非ASCII字符(rrseria*l_test_utility
f.e.)使用*
通配符.
You can use git branch --list rrseria*
to list only the branches whose names start with rrseria
. If there are more than one you can use a more specific pattern, using the *
wildcard for the non-ASCII characters (rrseria*l_test_utility
f.e.).
此命令显示要删除的分支的名称.
This command displays the name of the branch you want to delete.
如果您使用的是Linux或macOS,则可以使用其输出来创建Git命令来删除该分支:
If you are on Linux or macOS, you can use its output to create the Git command to delete that branch:
git branch -d $(git branch --list rrseria*)
或者您可以使用鼠标从git branch --list
的输出中复制终端窗口中的分支名称,并将其粘贴(回到终端窗口中)以创建git branch -d
命令.
Or you can use the mouse to copy the branch name in the terminal window from the output of git branch --list
and paste it (back into the terminal window) to create the git branch -d
command.
或者您可以使用您喜欢的文件管理器在.git/ref/heads
目录中导航并删除名称与分支名称匹配的文件(这是git branch -d
在后台执行的操作).
Or you can use your favorite file manager to navigate in the .git/ref/heads
directory and remove the file whose name matches the branch name (this is what git branch -d
does in the background).
之后,您必须将删除操作推送到远程存储库:
After that you have to push the deletion to the remote repositories:
git push origin --prune refs/heads/*
如果您有多个遥控器,则对每个遥控器重复上面的命令(输入其名称而不是origin
).
If you have more than one remote then repeat the command above for each of them (put its name instead of origin
).
这篇关于用任何名称而不是名称删除git branch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!