-
-
Save knu/111055 to your computer and use it in GitHub Desktop.
# Rename tags named foo-bar-#.#.# to v#.#.# and push the tag changes | |
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done |
you can greatly speed this up by pushing and pruning all remote tags at once:
# make sure your tags are up to date
git fetch origin
# rename all tags
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git tag -d $t; done
# synchronise with the server
git push --tags --prune origin refs/tags/*
you can greatly speed this up by pushing and pruning all remote tags at once:
# make sure your tags are up to date git fetch origin # rename all tags git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git tag -d $t; done # synchronise with the server git push --tags --prune origin refs/tags/*
no matches found: :refs/tags/*
This changes x.y.z
to x/y/z
, but won't delete tags that are already in new format
# make sure your tags are up to date
git fetch origin
# rename all tags
git tag -l | while read t; do n=$(echo $t | sed "s?\.?/?g"); if [[ "$n" != "$t" ]]; then git tag $n $t; git tag -d $t; git push origin :refs/tags/$t ; done
This changes build/n
to build/0n
(e.g.: build/8
-> build/08
).
git tag -l | while read t; do n=$(echo $t | sed "s?\/?/0?g"); git tag $n $t; git tag -d $t; done
Rename all vx.y.z
tags to x.y.z
:
git tag -l | while read t; do n="${t#?}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done
Don't forget to turn off CI/CD, if it's based on the tags ;)
If you have a mixture of vx.y.z and x.y.z tags, the first command will add a v to your existing 'v' tags, creating vvx.y.z tags...
This shell script solves that issue:
#!/bin/bash
# Get all of the repo's tags
all_tags=$(git tag)
# Loop through all tags
for tag in $all_tags; do
# Only process tags not starting with "v"
if [[ $tag != v* ]]; then
# Create the vx.y.z tag
git tag v$tag $tag
# Delete the x.y.z tag
git tag -d $tag
# Pushes the new vx.y.z tag and deletes the x.y.z tag remotely
git push origin v$tag :$tag
fi
done
# Push all tags, shouldn't be necessary, just there as backup
git push --tags
Renamed all my
x.y.z
tags tovx.y.z
, thanks!