我有一个包含很多以 "v1.2.3-rc-4" 格式命名的标签的 git 存储库,我想自动将它们重命名为 "1.2.3-rc4"。这些标签在本地和远程存储库中都存在。
需要澄清一点,版本号中的数字组件应视为变量。上述值仅用于演示标记格式。
是否有一种方法可以自动化此更改?
需要澄清一点,版本号中的数字组件应视为变量。上述值仅用于演示标记格式。
是否有一种方法可以自动化此更改?
--shell
选项的git for-each-ref
命令来评估引用。#!/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
对于一个或少数标签,请按照以下3个步骤进行。对于大量标签,可以修改上述脚本以使用下面的3个步骤作为替代解决方案。
command: git rev-parse <tag name>
example: git rev-parse v0.1.0-Demo
example output: db57b63b77a6bae3e725cbb9025d65fa1eabcde
command: git tag -d <tag name>
example: git tag -d v0.1.0-Demo
example output: Deleted tag 'v0.1.0-Demo' (was abcde)
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>
当本地 git 准备好更改标签名称后,这些更改可以推回到源代码库,以供其他人使用。