How to filter git log by tag?

Viewed 6166

I'm attempting to filter git log by tags. I have tried using --tags="3.5.0", as per the documentation, but it doesn't work as it returns all commits, both before and after the tag.

How am I suppose to use this?

2 Answers

I ran into (I think) this same issue with my own project. In my case, I have several tag "categories", each with its own specific versioning, and when I get successful build, I want to find the most recent tag, extract the version, increment it, and tag the current commit with that new version identifier.

I'm not 100% clear on your goal, but here is some code that will spit out the most recent commit id whose tag matches the specified regular expression:

tagRegex='foo'; # fill in your tag pattern here
git log --format='%h %D' | sed -n "/ tag: .*$tagRegex/ {s/ .*//; p;q;}";

My tags are of the form category-v1.2.3, and I'm interested in the semantic version attached to the tag rather than the commit ID, so I use this:

git log --format='%D' | sed -n "/^tag: .*$tagRegex/ {s/.*-v//; p;q;}";
Related