Reputation: 3282
I've tagged a commit with a lightweight tag, and pushed that tag to a remote repo, shared with other developers. I have now realised I should have annotated it so that it appears in git describe
.
Is there a way to convert it/re-tag the commit without breaking things?
Upvotes: 55
Views: 13277
Reputation: 578
Convert all tags to annotated (based on Charles Bailey's example and Ferenc Wágner's comment):
for tag in $(git tag -l); do git tag -a -f $tag $tag^0 -m $tag; done
git push --tags --force
Upvotes: 6
Reputation: 791869
A lightweight tag is just a 'ref' that points at that commit. You can force-create a new annotated tag on top of the old tag:
git tag -a -f <tagname> <tagname>
As of Git v1.8.2, you need to use --force
to replace any tags on a remote with git push
, even if you are replacing a lightweight tag with something that is effectively a fast-forward or a true tag object pointing at the same commit as the existing tag reference.
git push --force origin <tagname>
Upvotes: 44
Reputation: 5980
You can also simply use git describe --tags
to also include lightweight tags in the search.
Upvotes: 4
Reputation: 9224
Based on Charles' answer and on this blog post, I think it is better to use something like this:
#!/bin/sh
tag=$1
date="$(git show $tag --format=%aD | head -1)"
GIT_COMMITTER_DATE="$date" git tag -a -f $tag $tag
Upvotes: 25