更改git存储库中标签的命名约定?

Lea*_*yes 4 git

我有一个git存储库,其中包含许多格式为“ v1.2.3-rc-4”的标签,我想将其自动重命名为“ 1.2.3-rc4”。标记同时存在于本地和远程存储库中。

我要澄清的是,版本号中的数字部分应视为变量。以上值仅用于说明标签的格式。

有没有办法自动执行此更改?

Von*_*onC 5

要列出所有标签,我建议git for-each-ref使用eval refs--shell选项。 将其与单线组合以重命名/删除标签

#!/bin/sh

git for-each-ref --shell --format="ref=%(refname:short)" refs/tags | \
while read entry
do

    # assign tag name to $ref variable
    eval "$entry"

    # test if $ref starts with v
    ref2="${ref#v}"
    if [[ "${ref}" != "${ref2}" ]]; then

        # rename/delete tag
        git push origin refs/tags/${ref}:refs/tags/${ref2} :refs/tags/${ref}
        git tag -d ${ref}
    fi

done
Run Code Online (Sandbox Code Playgroud)