Git标记语法:为什么有些标记带有-破折号而有些带有-2? [英] Git Flag Syntax: why do some flags have -one dash and some have --two?
问题描述
我正在学习Git,并且无法使用 查找 任何 解释 标记 语法.
I am learning Git and have been unable to find any explanation of the flag syntax.
我不是指裸双破折号"
I'm not referring to the "bare double dashes"
--
据我们所知,
表示接下来的事情不是一种选择.我指的是各种实际标志,有时带有一个破折号,有时带有两个破折号.
which, as we know, indicate that what follows is not an option. I'm referring to various actual flags which sometimes have one dash, and sometimes have two.
git log -2 -p -U1 --graph
带有一个破折号和两个破折号的标志之间有什么区别?双破折号表示什么?
What is the difference between a flag with one dash and two dashes? What does the double dash indicate?
For example, the following two flags are identical, (according to this):
-q
--quiet
为什么破折号不同?如果我输入了错误的号码怎么办?
Why the different number of dashes? What if I put the wrong number?
推荐答案
我的理解是git遵循标志的标准" Linux约定.那就是:
My understanding is that git follows the 'standard' Linux convention for flags. That is:
- 短"标志的破折号:通常是一个字符标志,但有时带有单个字符的标志,然后是代表该标志参数的其他字符(例如,
git log -SFoo
,其中Foo
是该标志的参数-S
标志).这些标志可以是也可以不是其他较长标志的缩写形式. - "long"标志的两个破折号:多字符标志,通常是英语单词.如果这些标志接收参数,则该标志与标志之间用
=
符号(例如git log --author=Peter
)分隔.
- one dash for 'short' flags: generally one character flags, but sometimes flags with a single character, then further characters which represent a parameter to the flag (e.g.
git log -SFoo
, in whichFoo
is a parameter to the-S
flag). These flags may or may not be abbreviated forms of other, longer flags. - Two dashes for 'long' flags: multi-character flags which are usually an English word. If these flags receive parameters, it is separated from the flag by an
=
sign (e.g.git log --author=Peter
).
这是为什么":这是嵌入在Linux世界中的约定. Git来自这个世界,因此遵循惯例. 长标记的两个破折号,短标记的一个破折号"规则应指导您确定标记使用多少个破折号.
This is the 'why': it is a convention which is embedded in the Linux world. Git comes from this world, so it follows the convention. The 'two dashes for a long flag, one for a short flag' rule should guide you as to how many dashes to use for a flag.
至于为什么会有重复的长和短标志,例如--quiet
和-q
,它只是提供助记符或简洁性的选项. --quiet
更容易记住,但-q
习惯于键入和进行心理分析时则更快.例如,我经常键入git commit -m "...blah"
,如果每次必须输入git commit --message='...blah'
来使命令长度加倍,它就会让我感到不安.
As for why there are duplicate short and long flags, such as --quiet
and -q
, it's just to provide the option of either mnemonic convenience or terseness. --quiet
is easier to remember, but -q
is quicker to type and mentally parse if you're used to it. For instance, I type git commit -m "...blah"
so frequently it would get on my nerves if I had to double the length of my command every time by entering git commit --message='...blah'
.
我没有遇到过任何在两个破折号和一个破折号的情况下表现不同的git标志,因此通常如果您为一个破折号标志输入两个破折号,或者反之亦然,则不会有任何无法弥补的坏处发生这种情况,git只会抱怨您的标志而无所事事.
I haven't come across any git flags which behave differently given two dashes and one dash, so generally if you enter two dashes for a one-dash flag or vice versa, nothing irreparably bad will happen, git will just complain about your flags and do nothing.
当然,git有很多命令,每个命令都有很多标志,因此所有这些规则可能都有例外.他们一般都应该持有.
Of course, git has a vast number of commands, each with a vast number of flags, so it is possible that there are exceptions to all these rules. They should generally hold though.
这篇关于Git标记语法:为什么有些标记带有-破折号而有些带有-2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!