【问题标题】:Git describe fails to return most recent annotated tagGit描述无法返回最新的注释标签
【发布时间】:2015-11-22 03:38:56
【问题描述】:

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

我在添加单元测试的过程中,注意到git describe --abbrev=0 无法检索到最新的标签,只有当几个git tag -a <tag> -m <msg> 依次运行时。

我认为这与为同一提交创建的这些标签有关,但我认为 annotated 标签不应该是这种情况。

预期行为:

git tag 1 -m v1; sleep 1; git tag 2 -m v2; sleep 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

【问题讨论】:

标签: git shell unit-testing git-tag


【解决方案1】:

我发现在每次提交时强制执行 一个 注释标签更容易。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-15
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多