Given a Git revision, how can I find the tags it sits between?

Viewed 62

Given a revision, say fed3245, how can I find the tags 3.3 and 3.3.1 that come before and after fed3245?

2 Answers

You can find all tags before the revision by the following command:

git tag --contains fed3245

Similarly, the tags after that revision by:

git tag --no-contains fed3245
git describe --abbrev=0 --contains fed3245 
git describe --abbrev=0 $_

git describe by default works only off annotated tags, to control what refs it looks at see its docs. Edit: I see the no-abbrev logic seems a little bugged with --contains, you'll have to strip the ancestry refs, brute force workaround is

c=`git describe --abbrev=0 --contains fed3245`; echo ${c%%[~^]*}
git describe --abbrev=0 fed3245
Related