Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a lightweight tag be converted to an annotated tag?

Tags:

git

git-tag

tags

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?

like image 621
Stuart K Avatar asked Feb 15 '11 10:02

Stuart K


People also ask

How do you make an annotated tag?

To create an annotation tag you just need to add “-a” with the git tag command and “-m” to specify the message. $ git tag -a v1.

How do you tell if a tag is lightweight or annotated?

If the tag is an annotated tag, you'll see the message and the tag object, followed by the commit. If the tag is a lightweight tag, then you'll see only the commit object. If the current commit exactly matches that of a tag, then only the tag name is printed.

What is the difference between annotated and unannotated tags?

The difference between the commands is that one provides you with a tag message while the other doesn't. An annotated tag has a message that can be displayed with git-show(1), while a tag without annotations is just a named pointer to a commit.

Which command is used to create an annotated tag?

To create a Git tag with a message, use the “git tag” command with the “-a” option for “annotated” and the “-m” option for message. Note : if you don't provide the “-m” option, your default text editor will open in order for you to type the tag message.


1 Answers

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> 
like image 169
CB Bailey Avatar answered Sep 29 '22 14:09

CB Bailey