Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I sign a git tag after it was created?

Tags:

git

sign

I created a tag and forgot to sign it, then pushed the tag to GitHub. Is it possible to just sign that tag retroactively, or do I have to create a new tag?

I have read the man page for git tag and googled a bit, but have come up with no clues that adding a signature to an already existing tag is possible.

like image 916
herzbube Avatar asked Aug 17 '14 08:08

herzbube


People also ask

Can you commit to a git tag?

You can't put a new commit into an existing tag without breaking an important Git guideline: Never(*) modify commits that you have published. Tags in Git aren't meant to be mutable. Once you push a tag out there, leave it alone.

Which command is used to sign a tag in git?

It's easy to sign tags with the addition of the -s option to the git tag command. Remember that the tag will be assigned to the most recent commit. Well done!

Can git tag be updated?

We are required to delete/update branches or delete/update files etc. Similar to this, sometimes, we are required to update the tags in Git. Updating a tag will take your tag to another commit. For example, we can update the tag v1.


1 Answers

No you would need to::

  • replace it with a tag using the same name:

      git tag <tag name> <tag name> -f -s
    
  • but first set the committer date, in order to not change the date

      set GIT_COMMITTER_DATE="$(git log -1 --format=%aD <tag_name>)"
    

As mrts adds in the comments, since the tag was already pushed:

You also need to force push the updated tag with git push origin <tag_name> -f

like image 60
VonC Avatar answered Oct 12 '22 12:10

VonC