git commit -a -m "commit msg"可以缩写为git commit -am "commit msg"并按预期工作吗?
基本上,选项是否可以作为“短”开关给出,并让最后一个开关接受参数?
发布于 2011-05-18 03:06:38
是。
编写良好的Unix命令允许您将多个单字母选项合并到单个连字符后面,前提是除了组中的最后一个选项之外,其他选项都不能带参数。Git就是这些写得很好的命令之一。
许多没有花太多时间研究Unix shell的人没有意识到这一点,不幸的是,有时这些人最终编写的命令行实用程序不使用标准的getopt(3)来解析他们的选项,并且最终编写了自己的解析器,不允许您以这样的标准方式合并选项。所以有一些写得很差的命令不允许这样做。幸运的是,git是而不是这些写得很差的命令之一。
发布于 2011-05-18 03:05:07
你为什么不试一试呢?
$ 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(-)日志为:
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(-)所以一切都很好。
但是:如果你想让官方在git上这样做,请查看gitcli手册页。它写道:
拆分短选项以分隔单词(首选git foo -a -b而不是git foo -ab,后者甚至可能不起作用)
因此,您的里程可能会有所不同,单独的形式是git团队的首选。
发布于 2011-05-18 03:12:15
我猜想发帖者问这个问题是因为他不能访问Git,因为尝试它显然比发布问题更容易。值得他称赞的是,我实际上曾努力在Git文档中找到规范的答案(请注意,没有Google的帮助),但失败了。
$ git commit -am "yay"
# On branch master
nothing to commit (working directory clean)请记住,Git是由Linux的创建者Linus Torvalds编写的。如果有人要严格遵守POSIX guidelines,那就是他...您将注意到,用于标记结束选项和参数开头的双破折号(--)也是Git语法的一部分:
git log -n 10 -- some/file.txt从git log手册页:
[--] <path>…
    Show only commits that affect any of the specified paths. To prevent 
    confusion with options and branch names, paths may need to be prefixed
    with "-- " to separate them from options or refnames.https://stackoverflow.com/questions/6036667
复制相似问题