I am about to release the first version of my first git-managed project and am going to tag it with an annotated tag ("first alpha release"). Later on, to find out which was the first alpha release, I would like to search the contents of the tag annotations for "first alpha". How do I do so?
I know git log --grep
will search the contents of commit messages and git show
will tell me the contents of a tag annotation, but I can't figure out from the manpages or Google what command will do a search over tag annotations. Do I have to dump the records where the tag annotations are stored and search using another tool? I am envisioning git show $(git tag)|grep "first alpha"
and hoping there is a better way.
This does use external grep
but seems to be more elegant than parsing the output of git show:
git tag -l -n | grep "first alpha"
and you will get very nicely the output:
test_1.2.3 first alpha
Note the -n flag, here I assume your annotation are one line long. For longer messages you will need to give a number after -n (lets say -n99) and will be more complicated regarding the grep flags. https://www.kernel.org/pub/software/scm/git/docs/git-tag.html
One way to search multiline annotations is with gawk
(example bash
command line shown):
git tag -l -n99 | gawk -v pat='<some regex>' -- '/^\S/ {tag=$1} $0~pat { print tag }'
/^\S/ {tag=$1}
saves each tag name in turn, and $0~pat { print tag }'
prints the tag name when a match is found.
You need git show
on the dereferenced tag for exploring the content of the annotated tag "first alpha release
":
git show $(git show-ref -d -s --tags "first tag release"|tail -1| awk '{print $1}')
That being said, a git show directly with the tag would give the same result, except for the tag metadata displayed first.
git show $(git tag|grep "first alpha")
That would show the content of all tags whose tag name includes "first alpha".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With