开发者

Delete a branch starting with a hyphen

I managed to create a branch in git called '-f'

e.g.

$ git branch
* (no branch)
   -f

How do I delete the dang thing? git branch -d -f won't work, nor will git branch -d '-f' or even git branch -d -f 开发者_运维知识库-f


git branch -d -- -f

The -- symbol in general will stop parsing of command line options with many Linux tools.

Another way is

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

but git-update-ref is rather dangerous.


Not sure if this will work, but a -- argument in Unix/Linux-style commands often tells the command that you're done passing options, and now you're passing real arguments:

git branch -d -- '-f'


I created a branch accidentally with the following:

git branch –show-current

I was able to use grep and xargs to specify a unique pattern to delete it:

git branch | grep "show-current" | xargs git branch -D


I foolishly named a branch starting with a hyphen, and then checked out master. I didn't want to delete my branch, I had work in it.

Neither of these worked:

git checkout -dumb-name

git checkout -- -dumb-name

"s, 's and \s didn't help either.

This worked: go into your working copy's .git/refs/heads, find the filename "-dumb-name" (or whatever) and get the hash of the branch. Then:

git checkout {hash}
git checkout -b brilliant-name
git branch -d -- -dumb-name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜