我有一个git存储库,其中包含许多格式为" v1.2.3-rc-4"我想自动重命名为" 1.2.3-rc4"。标签存在于本地和远程存储库中。
我应该澄清版本号中的数字组件应该被视为变量。以上值只是为了演示标签的格式。
有没有办法让这种变化自动化?
答案 0 :(得分:4)
要列出所有代码,我建议使用--shell
选项git for-each-ref
推荐to eval refs。
将其与one-liner to rename/delete a tag结合使用。
#!/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
答案 1 :(得分:0)
对于一个或几个标签,请遵循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做好了标记名称更改的准备,就可以将这些更改推回原始位置,以供其他人使用。