2

I need to get list of commit ids between two known commits. I used the following command:

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

It works flawlessly until there is a merge commit. I.e.:

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

The output is as follows:

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

e24d2c4292baef4106976373ff3d01341834648d
92187d9a1002027c7d99824f2561467692bfd6b3

When I change the show command and use log instead:

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

Notice there is no empty line after the first commit. I'm not fanatic about using git show over git log - I event don't remember where I got this idea from. But this extra empty line caused my program failure and I wonder if it has any special meaning.

Git version 1.9.5.

fracz
  • 20,536
  • 18
  • 103
  • 149

2 Answers2

3

I don't see anything in the manual page explaining why that blank line is there. However, if you are passing the output to another program, you don't want the porcelain commands anyway, because the output formats are subject to change. The command you want is

git rev-list c36a37b...eef755e

Update: to your specific question -- does it have any meaning -- my answer is none that you can count on, because (a) it isn't mentioned in the manual page, and (b) the output of git show isn't intended to be parsed by other programs.

gatkin
  • 1,902
  • 12
  • 12
0

Could this (from git show docs) hold any clues ?

    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:
SherylHohman
  • 16,580
  • 17
  • 88
  • 94