问题
I wrote a function that uses git annotated tags to create new releases and/or bump semver style version numbers for my project.
I am in the process of adding unit tests and noticed that git describe --abbrev=0 fails to retrieve the most recent tag, only when several git tag -a <tag> -m <msg> are run in a sequence.
I thought this has to do with these tags being created for the same commit, but I think that should not be the case for annotated tags.
Expected behavior:
git tag 1 -m v1; sleep 1; git tag 2 -m v2; sleep 1; git tag 3 -m v3
git describe --abbrev=0
3
Reproduce problem:
git tag 1 -m v1; git tag 2 -m v2; git tag 3 -m v3
git describe --abbrev=0
1
回答1:
I found it was easier to enforce one annotated tag per commit.
First, retrieve the last annotated tag with --abbrev=0, check whether the current commit contains it and delete it if that's so.
last_version=$(git describe --abbrev=0)
if git tag --contains $(git rev-parse HEAD) | grep -q "^$last_version\$"; then
git tag -d $last_version
fi
git tag $version -m $msg
来源:https://stackoverflow.com/questions/33851344/git-describe-fails-to-return-most-recent-annotated-tag