所以我的问题是--global
也是一个开关吗?开关也可以作为参数吗?
已更新:
这本书说--global
是一个开关,所以我假设-a
也是一个开关,我们可以将其用作git help -a
,但不能将其用作{{1 }},根据语法应该有效吗?
答案 0 :(得分:4)
所有Git实际命令中,开关都是在之前传递的所有参数:请参见docs/git
git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|-P|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>]
<command> [<args>]
您可以在<command> [<args>]
--global
是git config
命令的开关,seen here,而不是单独的“ git
”开关。
在commit 0a8365a; May 2005, Git v0.99中引入了“开关”一词
diff-tree
:修复并扩展参数解析我们使用“
--
”标记命令行开关的结尾,而不是“-
”。
这与double-hyphen command-line convention内联,即I explained here,如果非选项参数以连字符开头,则很有用。
-- optional separator, followed by arguments
v
git -p config --global -- user.name
^^ ^^^^^^^^
| |_ switch for the git config subcommand.
|
switch for the git command
答案 1 :(得分:1)
通常,以连字符开头的命令行参数称为开关。 (但是即使有了这种“定义”,我还是会在这种情况下而不是用技术术语来考虑“开关”行话。)
“开关”通常会更改命令的次要方面或其操作模式。
由于git
命令具有许多子命令,因此您可以具有通常适用于该命令的开关(这些是git
和子命令之间的开关)以及适用于该子命令的开关-command(这些命令在子命令之后)。
举个例子
git -p config --global user.name "Rick"
-p
是适用于一般命令的开关;
--global
是适用于子命令的开关。