In git, list all tags since some tag
Asked Answered
D

3

7

I'm using tags to identify release versions and to identify "development complete" commits for tasks. Doing a git tag I get a list like the following.

> git tag
v0.1.0
task_1768
task_2011
task_1790
task_1341
v0.1.1
task_2043
task_2311
v0.1.2

Assuming that all tags point to commits on master branch, is there a way to list all tags since some tag? For example, to generate a list of all tasks included in the v0.1.2 release -- I'm looking for something like the following (which is not an actual command).

> git tag -l "task_*" --since v0.1.1

To get output like the following.

task_2043
task_2311

Is there a way to do this with git tag?

Is there a way to do this with git rev-list?

(Or some other git command?)

UPDATE

Based on the answers and comments the following is what I'm currently using.

> git log v0.1.1.. --decorate | grep -Eow 'tag: ([a-zA-Z0-9.-_]*)' | awk '{ print substr($0, 6); }'
task_2043
task_2311
v0.1.2

> git log v0.1.1.. --decorate | grep -Eow 'tag: ([a-zA-Z0-9.-_]*)' | awk '{ print substr($0, 6); }' | grep -Eo 'task_.*'
task_2043
task_2311

SECOND UPDATE

New selected answer. This is exactly what I was looking for initially. Much more elegant.

> git tag --contains v0.1.1
v0.1.1
task_2043
task_2311
v0.1.2

> git tag --contains v0.1.1 | grep -Eo 'task_.*'
task_2043
task_2311
Dermatoglyphics answered 10/1, 2013 at 0:5 Comment(3)
When you say "since" do you mean "all tags that point to commits not reachable from master" or do you mean "all tags that point to commits with a commit/authorship date newer than the one pointed to by master?" The two are different and will yield different results.Ulloa
Good question. I mean "all tags that point to commits with a commit/authorship date newer than the one pointed to by v0.1.1."Dermatoglyphics
I'm on my way out so I can't draft a solution at the moment, but I'm pretty sure that there is no one Git command that will do this. You will likely need to write a short shell script that iterates through the output of git tag, fetches the commit (or authorship) timestamp from each one as well as from HEAD and compares the two.Ulloa
B
10

git tag --contains v0.1.1 will show you all tags that contain the given tag -- i.e. tags from which you can trace back in history and reach the given tag.

Bonkers answered 13/1, 2013 at 2:50 Comment(0)
W
4

you can provide a range for git log:

git log v1.1.0..

now you add the --decorate option which will list tags. There are other options you can add to log to limit the list to just the interesting ones or grep it for "tag":

git log v1.1.0.. --decorate | grep 'tag:'
Westbrooks answered 10/1, 2013 at 0:17 Comment(2)
+1 Nice and clean; something like git log v0.1.1.. --decorate | awk '/tag:/{sub(/)$/, "", $4); print $4}' is probably very close to the desired output.Wistrup
Here's what works for my purposes: git log v0.1.1.. --decorate | grep -Eow 'tag: (task_[a-zA-Z0-9.-_]*)' | grep -Eo 'task.*'Dermatoglyphics
W
2

You can use git rev-list to give you all revisions reachable by following the links from master, excluding any that can also be reached from v0.1.1:

git rev-list --tags master --not v0.1.1

You can then run that through git describe:

git describe --abbrev=0 --tags `git rev-list --tags master --not v0.1.1`

This may give you duplicate copies of the tags (and will likely include v0.1.1 itself), but it should be a start to getting the list you require.

Wistrup answered 10/1, 2013 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.