Git tip: finding a tag by annotation

Git tags can be annotated. An annotation is a message that will be associated to the tag, and that can be used to embed some extra information that might help remembering, months later, why you decided that a particular commit was worth tagging:

$ git tag -a v1.5.RC1 -m 'version 1.5 Release Candidate 1: iPhone support'

Tags can be listed:

$ git tag -l

But the result is a little bit disappointing, specially if you added annotations (hint: annotations will not be shown).

If you want to see your extra-meaninful messages added to your tags, you can do something like this:

$ git tag -l -n1

That basically provides either the annotation or the first line of the latest commit message associated with each tag.

You already know that searching for a particular tag, by tag name, is easy:

$ git tag -l 'v1.5.*'

But, what if you only remember part of the annotation, and you want to know the tag it was associated to? Well, it’s a matter of combining some of the previous examples, and a little bit of grep-foo:

$ git tag -l -n1 | grep "iPhone"

And that is one way you can search tags by annotation message.

Leave a Reply

Your email address will not be published.