command: git tag -d <tag name> example: git tag -d v0.1.0-Demo example output: Deleted tag 'v0.1.0-Demo' (was abcde)
步骤3:创建一个新标签,指向旧标签所指向的相同提交ID
1 2 3
command: git tag -a <tag name> -m "appropriate message" <commit id> example: git tag -a v0.1.0-full -m "renamed from v0.1.0-Demo" db57b63b77a6bae3e725cbb9025d65fa1eabcde example output: Nothing or basically <No error>
将本地的标签名更改推送到远程仓库:
1 2 3
command: git push origin :<old tag name> <new tag name> example: git push origin :v0.1.0-Demo v0.1.0-full example output: <deleted & new tags>
一键重命名别名法
在.gitconfig中添加别名:
1 2
[alias] renameTag = "!sh -c 'set -e;git tag $2 $1; git tag -d $1;git push origin :refs/tags/$1;git push --tags' -"
使用方法:
1
git renametag old new
复制并删除法(适用于附注标签)
1 2
git tag -a -m "`git cat-file -p old_tag | tail -n +6`" new_tag old_tag^{} git tag -d old_tag
为避免同步问题,建议先推送新标签,再删除旧标签:
1 2 3 4
git tag -a -m "`git cat-file -p old_tag | tail -n +6`" new_tag old_tag^{} git push --tags git tag -d old_tag git push origin :refs/tags/old_tag