可以缩短git开关选项吗?

Rya*_*wis 4 git

可以git commit -a -m "commit msg"缩短到git commit -am "commit msg"并按预期工作吗?

基本上,可以选择"短"开关,让最后一个开关接受参数吗?

Mat*_*Mat 5

你为什么不试试?

$ echo a > a; echo b > b
$ git init
Initialized empty Git repository in /home/me/tmp/a/.git/
$ git add a b
$ git commit -m "hello"
[master (root-commit) 184d670] hello
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 a
 create mode 100644 b b > a; echo a > b
$ git commit -am "other commit"
[master 4ec9bb9] other commit
 2 files changed, 2 insertions(+), 2 deletions(-)
Run Code Online (Sandbox Code Playgroud)

日志是:

commit 4ec9bb943eb230923b4669ef6021124721cb9808
Author: me
Date:   Tue May 17 21:02:41 2011 +0200

    other commit

 a |    2 +-
 b |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

commit 184d670b7862357cd8a898bfcaa79de271c09bd7
Author: me
Date:   Tue May 17 21:02:23 2011 +0200

    hello

 a |    1 +
 b |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
Run Code Online (Sandbox Code Playgroud)

一切都很好.

但是:如果你想让官方为git做这个,请查看gitcli手册页.它指出:

拆分短选项以分隔单词(更喜欢git foo -a -b到git foo -ab,后者甚至可能不起作用)

所以你的里程可能会有所不同,git团队会选择单独的表格.


Spi*_*iff 5

是.

编写良好的Unix命令允许您在单个连字符后面合并多个单字母选项,只要除了组中的最后一个选项之外的任何选项都不能使用参数.Git是这些编写良好的命令之一.

许多没有在Unix shell中花费太多时间的人都没有意识到这一点,不幸的是,有时这些人最终会编写不使用该标准getopt(3)来解析其选项的命令行实用程序,并最终编写自己的解析器不允许您以标准方式合并选项.所以有一些写得不好的命令不允许这样做.幸运的是,git 不是那些写得不好的命令之一.