Reputation: 439
I have a git repo with commits on the master branch, each of which may have multiple tags:
HASH: TAGS
hash7: [v6.0.0, foo1, foo2, foo3]
hash6: []
hash5: []
hash4: [v5.0.0, bar1, bar2, bar3]
hash3: [v4.0.0, baz1, baz2, baz3]
hash2: []
hash1: [v3.0.0, foobar1, foobar2, foobar3]
I have a github action that is triggered by the creation of version tag (v.*.*.*
). This action needs to be able to figure out the previous version tag. So, for example, if the action runs on hash7
(v6.0.0
), it should return v5.0.0
. If it runs on hash4
(v5.0.0
), it should return v4.0.0
, etc.
There are a number of stackoverflow questions that relate to this. I have tried various combinations of:
git describe --match 'v*' --tags
git rev-list --tags='v*' --max-count=1 --skip=1
git describe --tags --match "v*" --abbrev=0 git rev-list --tags="v*" --max-count=1 --skip=1
The latter, for example, when run on v6.0.0
gives the latest tag (v6.0.0
) when run without the skip option, but gives v4.0.0
when the skip option is set as 1.
I've done quite a bit of googling, but I can't find anything reliable.
To summarise, I'm after: The nearest version tag (not including the one attached to the commit that is currently at the HEAD), on this branch
Upvotes: 1
Views: 220