我知道这不是一个严格的编程问题,但它与 git 有关。我不小心在 git 中创建了一个名为的分支--track
(合并远程分支时我的选项顺序错误)
常规命令不起作用:
git branch -D "--track"
我试图用引号和反斜杠来逃避,但都不管用。
有任何想法吗?
我知道这不是一个严格的编程问题,但它与 git 有关。我不小心在 git 中创建了一个名为的分支--track
(合并远程分支时我的选项顺序错误)
常规命令不起作用:
git branch -D "--track"
我试图用引号和反斜杠来逃避,但都不管用。
有任何想法吗?
你试过了吗
git branch -D -- --track
? “ --
”通常是“接下来的不是一个选项,不管它的名字是什么”的约定
来自“ The Art of Unix Programming ”的“ Command-Line Options ”一节:
将双连字符识别为停止选项解释并按字面处理所有后续参数的信号也是常规的。
您会在其他(非必需的 Unix 相关)CLI(命令行界面)中找到该约定,例如cleartool:
如果非选项参数以连字符 (
–</code>) 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-
The P18 (a fast and flexible file preprocessor with macro processing capabilities and special support for internationalization) mentions that also and gives a good description of the general idea behind that convention:
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.
The OptionParser tool written in ruby also lays it out quite plainly:*
Option Parsing Termination
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"]
Note: sometimes, it takes three dashes and not two, especially when the CLI follows strictly the Gnu options styles:
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 aslong_options
and the Unix style options asshort_options
.
The compatibility is maintained by preceding the long_options with two dashes
Similar to the Unix style double-hyphen ’<code>--
',Gnu 风格有一个三连字符 '<code>---' 表示选项解析被停止并将剩余的文本视为参数(即从命令行逐字读取)
所以...如果 ' --
' 还不够(应该使用 Git 命令),请尝试 ' ---
'
git branch -D -- --track
我正在使用 msysgit 1.7.0.2,建议的解决方案不起作用:
git branch -D -- --track # 不起作用
没有报错,但分支仍然存在。我最终通过以下方式强行删除了分支:
rm .git/refs/heads/--track
双连字符在远程上对我不起作用,分支名称包含双引号和 & 符号。然而,包装名称引号并转义包含的引号做了这项工作:
git push origin --delete "123-my-branch-&-some\"quoted-text\""
和本地:
git branch -D "123-my-branch-&-some\"quoted-text\""
我有一个类似的问题,我不小心得到了一个“-r”分支。我不知道如何使用 git 命令删除它,所以我只是在 .git 文件夹中删除它:
$ cd .git/refs/head
$ ls *r
-r
$ rm "*r"
这个解决方案是安全的,因为它是列出的唯一以“r”结尾的分支,但它确实解决了问题......
您可以使用软件:sourcetree 可以删除您喜欢的任何分支。