Here's what I did, based on MrTux's comment:
List all the tags and their associated commits
git for-each-ref --sort -v:refname --format '%(objectname) %(objecttype) %(refname)
%(*objectname) %(*objecttype) %(*refname)' refs/tags
If an entry looks like this, then it's an annotated tag:
f844099a21d37a0139cbccd1f179113937d3fe69 tag refs/tags/v0.4.1
1639e13f12fac2c36b7d50661589990355c03419 commit refs/tags/v0.4.1^{}
If an entry looks like this, then it's a lightweight tag since there's no tag hash:
644adce83cdd25057fa865701c509d852d5d44d5 commit refs/tags/v0.4.0
refs/tags/v0.4.0^{}
To replace one annotated tag with a lightweight tag
(Using the example from above)
Delete the tag, e.g.
git tag -d v0.4.1
Create a new tag
git tag v0.4.1 1639e13f12fac2c36b7d50661589990355c03419
- Make sure to use the commit hash of the original tag and not the tag hash
- Make sure not to use
-a
, -s
, or -u
as these will create annotated tags
To replace all annotated tags with lightweight tags
git for-each-ref --format="%(refname:short) %(*objectname)" "refs/tags/*" | while IFS= read -r line; do tag=$(echo "$line" | cut -f 1 -d " "); hash=$(echo "$line" | cut -f 2 -d " "); git tag -d $tag && git tag $tag $hash; done