Git命令中的“开关”是什么?

时间:2020-02-07 04:33:34

标签: git

我正在读一本书,其中显示了git命令的语法: enter image description here

enter image description here

所以我的问题是--global也是一个开关吗?开关也可以作为参数吗?

已更新:

这本书说--global是一个开关,所以我假设-a也是一个开关,我们可以将其用作git help -a,但不能将其用作{{1 }},根据语法应该有效吗?

2 个答案:

答案 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>]

之前看到所有可能的开关

--globalgit 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是适用于子命令的开关。

相关问题