29

I need a git command that would output only the message of a given annotated tag. It's almost possible with git tag -ln:

$ git tag -ln v1.3.7
v1.3.7          Here be annotations

It's just that I don't want the tag and whitespace in the beginning, and throwing a regex at this feels like overkill. Is there any built-in flag i could use? I'm using git version 1.8.3.2.

Some of the answers at Print commit message of a given commit in git use git show --format=%B. I can't seem to restrict output to only the message, neither for commits or tags.

Community
  • 1
  • 1
lime
  • 6,901
  • 4
  • 39
  • 50
  • 2
    The answer does not necessarily need to use the format flag, if a different solution exists. – lime Oct 01 '18 at 11:54
  • 1
    The question you linked to is quite different. It asks for _a list of all tags_ (with message included). I'm asking for _a single tag_, and with all details except the message omitted. – lime Oct 01 '18 at 11:55

2 Answers2

35

I'm not sure what version of git this requires, but with recent versions you can also do:

git tag -l --format='%(contents)' <tag name>

to get only the tag message by itself.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
keitwb
  • 541
  • 5
  • 8
6

I got just the message (but the message included some extraneous stuff like PGP signature and signed-off-by lines) when I said:

git show -s --format=%B <tag>

Note the -s.

Wolf
  • 4,254
  • 1
  • 21
  • 30
  • 3
    Yes, I'd have expected this to do what I want. The extra stuff is in the way though. You'd think since `git tag -ln` excludes it, it would be possible to leave out from `show` as well. – lime Feb 04 '14 at 20:09