Git描述无法返回最近注释的标签 [英] Git describe fails to return most recent annotated tag

查看:137
本文介绍了Git描述无法返回最近注释的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个函数,它使用 git 带注释的标签为我的项目创建新版本和/或撞击semver风格的版本号。



我正在添加单元测试,并注意到 git describe --abbrev = 0 无法检索最近的标记,仅 当几个 git标签-a< tag> -m > 按顺序运行。



我认为这与为相同提交创建的这些标记有关,但我认为这不应该是注释标签的情况。



预期行为:

  git tag 1 -m v1;睡1; git tag 2 -m v2;睡1; git tag 3 -m v3 
git describe --abbrev = 0
3

重现问题:

  git tag 1 -m v1; git tag 2 -m v2; git tag 3 -m v3 
git describe --abbrev = 0
1


解决方案

我发现每次执行一次注解标记更容易。

首先,检索最后一个带有 - abbrev = 0 的注释标签,检查当前提交是否包含它并删除它。

  last_version = $(git describe --abbrev = 0)

如果git tag --contains $(git rev-parse HEAD) grep -q^ $ last_version\ $;然后
git tag -d $ last_version
fi

git tag $ version -m $ msg


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

解决方案

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

这篇关于Git描述无法返回最近注释的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆