更改git仓库中标签的命名约定? [英] Change naming convention of tags inside a git repository?
问题描述
我有一个git仓库,其中包含一些格式为v1.2.3-rc-4的标签,我想自动将其更名为1.2.3-rc4。标签存在于本地和远程仓库中。
I have a git repository which contains a number of tags with the format "v1.2.3-rc-4" which I would like to automatically rename to "1.2.3-rc4". The tags exist in both the local and remote repositories.
我应该澄清,版本号中的数字组件应该被视为变量。上面的值仅仅是为了演示标签的格式。
I should clarify that the numeric components in the version number should be treated as variables. The above values are simply to demonstrate the format of the tags.
有没有一种方法可以实现这种变化的自动化?
Is there a way to automate this change?
> git for-each-ref
与 - shell
选项。
将其与单行重命名/删除标签。
To list all tags, I would recommend git for-each-ref
with the --shell
option to eval refs.
Combine it with a 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
这篇关于更改git仓库中标签的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!