Delete broken branch in git
I have created branch with "git checkout -b mybranch". It seems that something went wrong, and now I can't delete it using "git branch -D mybranch". It says: error: branch 'mybranch' not found.
If git branch -D
really isn't working, then your only option is to side-step it and edit the git check-out's state yourself. You should go to the root-directory of your check-out (where the .git
directory is) and
.git/packed-refs
; if you see a line with your branch name then delete it .git/refs/heads
for a file named after your branch; if you see one, delete it I used git update-ref -d refs/heads/<branch name>
to fix this issue. Presumably, this does the same thing as what Rup suggests in the selected answer except it's interfaced via Git's CLI.
You obviously don't need to delete a branch that does not exist. Use git branch
to see a list of branches, if it's not in there, then there is no branch, and you don't need to delete it. Otherwise make sure to type the name correctly and git branch -D
should work.
Nevertheless you don't need to care much about a broken branch that might be still around but is inaccessible. Branches in Git are in fact simple 40 bytes files, so not really something you need to worry about.
链接地址: http://www.djcxy.com/p/26004.html上一篇: 这么多未使用的分支。 如何清理?
下一篇: 在git中删除损坏的分支