482

I want git to list all tags along with the full annotation or commit message. Something like this is close:

git tag -n5

This does exactly what I want except that it will only show up to the first 5 lines of the tag message.

I guess I can just use a very large number. What is the highest number I can use here? Is it the same on every computer?

UPDATE: I have had much time to think about this, and now I think I don't necessarily want to show the entirety of each message if some of them are extraordinarily long. I didn't really have any particular need that required me to see massive messages (other than my own propensity to be long winded in everything I write, including tag messages). I just didn't like the idea that it was not necessarily going to show me the whole message, as that made me feel like it was hiding information from me. But too much information can also be a bad thing.

still_dreaming_1
  • 8,661
  • 6
  • 39
  • 56

10 Answers10

465

Try this it will list all the tags along with annotations & 9 lines of message for every tag:

git tag -n9

can also use

git tag -l -n9

if specific tags are to list:

git tag -l -n9 v3.*

(e.g, above command will only display tags starting with "v3.")

-l , --list List tags with names that match the given pattern (or all if no pattern is given). Running "git tag" without arguments also lists all tags. The pattern is a shell wildcard (i.e., matched using fnmatch(3)). Multiple patterns may be given; if any of them matches, the tag is shown.

Zubair
  • 5,833
  • 3
  • 27
  • 49
  • 6
    This will only print the first line of each annotation. – Paul Price Jan 07 '13 at 21:36
  • 3
    @Paul Price: only you have an annotation, otherwise it prints the commit message. Agree this is not *the* answer. – Ciro Santilli OurBigBook.com Apr 18 '13 at 13:47
  • The `-n` flag corresponds to the number of lines you want to have printed. Sadly the output isn't great so perhaps the `--column` flag would be best to output messages cleanly. – Olivier Lacan Aug 31 '14 at 17:52
  • 3
    According to the documentation, the `-l` option is to filter on a pattern. I don't see how that would be helpful here. Am I missing something? – still_dreaming_1 Sep 23 '14 at 15:03
  • 2
    @INTPnerd yes, the `-l` is totally superfluous here – Lambart Oct 02 '14 at 22:40
  • @still_dreaming_1 if you try running without -l, you'll get fatal: -n option is only allowed with -l. – Myer Jun 30 '15 at 17:58
  • 1
    @P.MyerNore You must be using a weird version of git or passing additional arguments to do something more than what this question is asking. But it is good to know that for certain situations the -l is needed. – still_dreaming_1 Jul 02 '15 at 15:30
  • My favorite command: list up to 99 lines for each tag, listing only tags which contain string "my string" somewhere in them: `git tag -l -n99 '*my string*'` – Gabriel Staples Sep 18 '21 at 00:26
169
git tag -n99

Short and sweet. This will list up to 99 lines from each tag annotation/commit message. Here is a link to the official documentation for git tag.

I now think the limitation of only showing up to 99 lines per tag is actually a good thing as most of the time, if there were really more than 99 lines for a single tag, you wouldn't really want to see all the rest of the lines would you? If you did want to see more than 99 lines per tag, you could always increase this to a larger number.

I mean, I guess there could be a specific situation or reason to want to see massive tag messages, but at what point do you not want to see the whole message? When it has more than 999 lines? 10,000? 1,000,000? My point is, it typically makes sense to have a cap on how many lines you would see, and this number allows you to set that.

Since I am making an argument for what you generally want to see when looking at your tags, it probably makes sense to set something like this as an alias (from Iulian Onofrei's comment below):

git config --global alias.tags 'tag -n99'

I mean, you don't really want to have to type in git tag -n99 every time you just want to see your tags do you? Once that alias is configured, whenever you want to see your tags, you would just type git tags into your terminal. Personally, I prefer to take things a step further than this and create even more abbreviated bash aliases for all my commonly used commands. For that purpose, you could add something like this to your .bashrc file (works on Linux and similar environments):

alias gtag='git tag -n99'

Then whenever you want to see your tags, you just type gtag. Another advantage of going down the alias path (either git aliases or bash aliases or whatever) is you now have a spot already in place where you can add further customizations to how you personally, generally want to have your tags shown to you (like sorting them in certain ways as in my comment below, etc). Once you get over the hurtle of creating your first alias, you will now realize how easy it is to create more of them for other things you like to work in a customized way, like git log, but let's save that one for a different question/answer.

still_dreaming_1
  • 8,661
  • 6
  • 39
  • 56
  • 4
    `git config --global alias.tags 'tag -n99'` – Iulian Onofrei Oct 30 '18 at 08:54
  • 1
    @IulianOnofrei, nice, I didn't know git allowed you to define aliases. I realize this is off topic, but I can't resist. This is what I am now using (placed in your .bashrc or something like that): `alias gtag='git for-each-ref --format="%(refname:short) %(taggerdate) %(subject) %(body)" refs/tags | sort -V'` – still_dreaming_1 Oct 31 '18 at 15:24
27

Mark Longair's answer (using git show) is close to what is desired in the question. However, it also includes the commit pointed at by the tag, along with the full patch for that commit. Since the commit can be somewhat unrelated to the tag (it's only one commit that the tag is attempting to capture), this may be undesirable. I believe the following is a bit nicer:

for t in `git tag -l`; do git cat-file -p `git rev-parse $t`; done
Community
  • 1
  • 1
Paul Price
  • 2,657
  • 30
  • 26
  • Mark's git show did not show patches for my usage. His command omits -p or --patch, but to be totally sure of skipping the diff, one can use: --no-patch. (on git v2.7.1/mac) – AnneTheAgile May 13 '16 at 15:58
16

Use --format option

git tag -l --format='%(tag) %(subject)'
14

It's far from pretty, but you could create a script or an alias that does something like this:

for c in $(git for-each-ref refs/tags/ --format='%(refname)'); do echo $c; git show --quiet "$c"; echo; done
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Is there a reason not to replace `git for-each-ref refs/tags/ --format='%(refname)'` with `git tag -l`? – Shai Berger Jan 29 '14 at 10:35
  • 1
    @ShaiBerger: in practice, I don't think so - I guess I was just thinking that `git tag` is porcelain and `git for-each-ref` is plumbing, so the output of the latter should be more stable for scripting. – Mark Longair Jan 29 '14 at 12:38
  • Based on this answer, I used git log instead of git show to get a prettier result: `for c in $(git tag -l); do git tag -l -n1 $c; echo Commit message: \`git log -n1 --format=%B --quiet "$c"\`; echo; done` – LucG May 05 '21 at 13:16
11

Last tag message only:

git cat-file -p $(git rev-parse $(git tag -l | tail -n1)) | tail -n +6
gaRex
  • 4,144
  • 25
  • 37
  • 3
    For anyone else happening upon this from google: If you want to show the message from a particular tag: `git cat-file -p | tail -n +6` – Aurelia Peters Jul 19 '18 at 17:08
6
git tag -l --format='%(contents)'

or

git for-each-ref refs/tags/ --format='%(contents)'

will output full annotation message for every tag (including signature if its signed).

  • %(contents:subject) will output only first line
  • %(contents:body) will output annotation without first line and signature (useful text only)
  • %(contents:signature) will output only PGP-signature

See more in man git-for-each-ref “Field names” section.

Envek
  • 4,426
  • 3
  • 34
  • 42
6

You can show messages of tags with this command

git tag -n

-n option for show message.

Eng_Farghly
  • 1,987
  • 1
  • 23
  • 34
Park JongBum
  • 1,245
  • 1
  • 16
  • 27
2

I prefer doing this on the command line, but if you don't mind a web interface and you use GitHub, you can visit https://github.com/user/repo/tags and click on the "..." next to each tag to display its annotation.

agouge
  • 147
  • 1
  • 3
0

Below command may provide more related info on tags

git tag --format='%(refname:strip=2)%09%(creatordate:short)%09%(authorname)%09%(subject)' --sort=-creatordate

Result lists tag, date, name, oneline:

R7.0 2023-06-28  John Doe  [APP]Modified for release
R6.5 2023-04-02  John Doe  [APP]Updated readme

To get full message, change subject in the command to contents.

The format is in '%(fieldname)'. For example, '%09' is '\t', '%0a' is '\n', %(color:red), etc. Details see

git help for-each-ref