显示提交ID时git show和git log之间的区别

时间:2015-04-02 15:10:45

标签: git git-log git-show

我需要在两个已知提交之间获取提交ID列表。我使用了以下命令:

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。

2 个答案:

答案 0 :(得分:3)

我在手册页中没有看到任何解释为什么有空行的原因。但是,如果要将输出传递给另一个程序,则无论如何都不需要瓷器命令,因为输出格式可能会发生变化。你想要的命令是

git rev-list c36a37b...eef755e

更新:针对您的具体问题 - 它是否有任何意义 - 我的回答是无法依靠,,因为(a)它不是在手册页中提到,(b)git show的输出不打算由其他程序解析。

答案 1 :(得分: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: