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 does not (and it should not) change tags behind users back. So if somebody already got the old tag, doing a git-pull on your tree shouldn't just make them overwrite the old one. If somebody got a release tag from you, you cannot just change the tag for them by updating your own one.
Tap the tag you wish to rename to bring up its task list. Tap the Title Bar at the top of the screen and then tap Edit tag. Tap the tag name field and edit the name. Tap Save.
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
Follow the 3 step approach for a one or a few number of tags. For large number of tags the above script can be modified to use the below 3 steps as an alternative solution.
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>
Once the local git is ready with the tag name change, these changes can be pushed back to the origin for others to take these.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With