2009-07-28 110 views
45

我知道这不是严格的编程问题,但它与git有关。删除命名错误的git分支

git branch -D "--track" 

我试图用引号逃跑:我不小心已经创造了混帐分支称为--track

常规命令不起作用(合并远程分支时,我得到的选项的顺序错了)和后退斜杠,但都没有工作。

任何想法?

+0

我想知道您是如何设法创建该分支的。它看起来不像你做过“git branch - --track”。还是你? – 2009-07-28 06:19:25

+3

这是违规行,我试图跟踪远程分支。 git branch -b --track origin/dev – Felix 2009-07-29 03:20:04

回答

79

你尝试

git branch -D -- --track 

?在“--”通常是公约“接下来是不是一种选择,它的名字”


从“The Art of Unix Programming”,部分“Command-Line Options”:

It is also conventional to recognize a double hyphen as a signal to stop option interpretation and treat all following arguments literally.

你会发现,约定在其他(没有必要的Unix相关)CLI(命令行界面)像cleartool

If a nonoption argument begins with a hyphen () character, you may need to precede it with a double-hyphen argument, to prevent it from being interpreted as an option:

cleartool rmtype -lbtype -- -temporary_label- 

P18(一种快速,灵活的文件与宏处理能力和国际化的特殊支持预处理器)提到,也并给出了总体思路是惯例背后一个很好的说明:写在

All option arguments passed to the commands start with a single hyphen.
All option arguments (if any) must precede all non-option arguments.
The end of the option arguments may be signaled using a double hyphen, this is useful if a non-option argument starts with a hyphen. Terminating the list of option arguments with a double hyphen works for all commands, even those that don't take any option arguments.

OptionParser工具红宝石也奠定了它一清二楚:*

选项解析终止

It is convention that a double hyphen is a signal to stop option interpretation and to read the remaining statements on the command line literally. So, a command such as:

app -- -x -y -z 

will not ‘see’ the three mode-flags. Instead, they will be treated as arguments to the application:

#args = ["-x", "-y", "-z"] 

注:有时,它有三个破折号和不是两个,尤其是当CLI严格遵循GNU的选择样式:

The Gnu style command line options provide support for option words (or keywords), yet still maintain compatibility with the Unix style options.
The options in this style are sometimes referred to as long_options and the Unix style options as short_options.
The compatibility is maintained by preceding the long_options with two dashes

Similar to the Unix style double-hyphen ’ -- ’, the Gnu style has a triple-hyphen ’ --- ’ to signal that option parsing be halted and to treat the remaining text as arguments (that is, read literally from the command line)

所以...如果 '--'是不够的(应该用Git命令),试试'---'

7
git branch -D -- --track 
4

我使用msysgit 1.7.0.2和建议的解决方案不起作用:

的Git分支-D - --track#不起作用

报道没有错误,但分公司仍然。我结束了通过强行删除分支:

rm。git/refs/heads/- track

1

双连字符不适用于我的远程分支名称,包含双引号和&符。但是包装名称引号和逃避包含引号做了工作:

git push origin --delete "123-my-branch-&-some\"quoted-text\"" 

和本地:

git branch -D "123-my-branch-&-some\"quoted-text\"" 
0

我有一个类似的问题,我意外地结束了一个“-r”分支。我无法弄清楚如何使用Git命令,所以我只是将其删除的文件夹git的删除它:

$ cd .git/refs/head $ ls *r -r $ rm "*r"

该解决方案是唯一安全的,因为它是唯一的分支中列出,在“R结束“但它确实解决了这个问题...

0

你可以使用软件mamed sourcetree,它可以删除你喜欢的任何分支。