Reputation: 26862
I run a private repository which uses lightweight tags, as it allows for easy testing and review before going public.
One of our tags was created with an incorrect name (v0.21.
vs v0.2.1
). Additionally, this tag was created as an annotated tag on accident. As such, editing the tag would modify its creation date, making our GitHub releases display in a non-chronological order.
I know it's possible to convert a lightweight tag to an annotated tag. Is it possible to do the reverse and downgrade an annotated tag to a lightweight tag?
Upvotes: 3
Views: 462
Reputation: 15995
Here's what I did, based on MrTux's comment:
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^{}
(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
-a
, -s
, or -u
as these will create annotated tagsgit 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
Upvotes: 1