2011-05-17 56 views

回答

5

是的。

精心編寫的Unix命令讓你合併一個連字符後面的多單字母選項,只要沒有的除了最後一個組中可以帶參數的選項。 Git是這些寫得很好的命令之一。

許多沒有花太多時間在Unix shell中的人並沒有意識到這一點,不幸的是,有時候這些人最終會編寫不使用標準getopt(3)來解析其選項的命令行工具,以及最終編寫自己的解析器,不允許你以這種標準方式合併選項。所以有一些寫得不好的命令是不允許的。幸運的是,git是而不是這些寫得不好的命令之一。

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(-) 

日誌是:

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富-a -b與git FOO -AB,後者甚至可能不工作)

所以你的里程可能會有所不同,而git團隊首選單獨表格。

+0

1+不錯的工作,但也可能是實現特定的或可能不會由早期版本的支持,從而可以參照也會更好 – mbx 2011-05-17 19:13:13

+1

優秀的評論,尤其是使用Git唐民不喜歡組合選項:-)更新我的帖子,以反映這一點。 – Mat 2011-05-17 19:19:06

1

我假設海報在問,因爲他無法訪問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. 
相關問題