Git describe fails to return most recent annotated tag

六眼飞鱼酱① 提交于 2019-12-10 23:09:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!