2015-04-02 81 views
2

我需要獲取兩個已知提交之間的提交id列表。我用下面的命令:顯示提交ID時git顯示和git日誌之間的區別

git show --format=format:%H --quiet commitA...commitB 

它工作完美,直到有合併提交。即:

* c36a37b 
|\ 
| * 92187d9 
* | e24d2c4 
|/ 
* eef755e 

輸出如下:

$ git show --format=format:%H --quiet c36a37b...eef755e 
c36a37b80caf2bae7b4833617443f4dfea8d8816 

e24d2c4292baef4106976373ff3d01341834648d 
92187d9a1002027c7d99824f2561467692bfd6b3 

當我改變show命令和使用log代替:

$ git log --format=format:%H --quiet c36a37b...eef755e 
c36a37b80caf2bae7b4833617443f4dfea8d8816 
e24d2c4292baef4106976373ff3d01341834648d 
92187d9a1002027c7d99824f2561467692bfd6b3 

通知有之後的第一承諾沒有空行。我並不狂熱使用git show而不是git log - 我的事件不記得我從哪裏得到這個想法。但是這個額外的空行導致我的程序失敗,我不知道它是否有任何特殊的含義。

Git版本1.9.5。

+0

?你能編輯你的問題並添加一個可重複的例子嗎? – Jubobs 2015-04-02 15:32:18

+1

版本已添加。每個合併提交的行爲就像那樣。 – fracz 2015-04-02 15:41:22

回答

3

我在手冊頁中沒有看到任何解釋爲什麼那個空白行在那裏。但是,如果將輸出傳遞給另一個程序,則無論如何都不需要瓷器命令,因爲輸出格式可能會發生變化。你想要的命令是

git rev-list c36a37b...eef755e 

更新:到您的具體問題 - 它沒有任何意義 - 我的答案是沒有,因爲(a)沒有提到它,你可以指望,在手冊頁中,和(b)git show的輸出不打算由其他程序解析。

0

請問這個(來自git show文檔)是否有任何線索?

format: 
... 

If you add a + (plus sign) after % of a placeholder, a line-feed is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string. 

If you add a - (minus sign) after % of a placeholder, all consecutive line-feeds immediately preceding the expansion are deleted if and only if the placeholder expands to an empty string. 

If you add a ` ` (space) after % of a placeholder, a space is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string. 

VS

tformat: 

    The tformat: format works exactly like format:, except that it provides "terminator" semantics instead of "separator" semantics. In other words, each commit has the message terminator character (usually a newline) appended, rather than a separator placed between entries. This means that the final entry of a single-line format will be properly terminated with a new line, just as the "oneline" format does. For example: 

    $ git log -2 --pretty=format:%h 4da45bef \ 
     | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/' 
    4da45be 
    7134973 -- NO NEWLINE 

    $ git log -2 --pretty=tformat:%h 4da45bef \ 
     | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/' 
    4da45be 
    7134973 

    In addition, any unrecognized string that has a % in it is interpreted as if it has tformat: in front of it. For example, these two are equivalent: 
您正在使用哪個的Git版本