gpt4 book ai didi

git - 删除命名错误的 git 分支

转载 作者:IT王子 更新时间:2023-10-29 00:45:11 27 4
gpt4 key购买 nike

我知道这不是严格意义上的编程问题,但它与 git 有关。我不小心在 git 中创建了一个名为 --track 的分支(我在 merge 远程分支时弄错了选项的顺序)

常规命令不起作用:

git branch -D "--track"  

我曾尝试使用引号和反斜杠进行转义,但都不起作用。

有什么想法吗?

最佳答案

你试过吗

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用 ruby​​ 编写的工具也很清楚:*

选项解析终止

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 命令),试试“---

关于git - 删除命名错误的 git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1192180/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com