January 11, 2011

Replace a Lightweight Git Tag with an Annotated Tag

When I released Jifty-DBI versions 0.63 and 0.64, I used a lightweight tag (a simple pointer to a commit) instead of an annotated tag (nearly the equivalent of a commit) to tag the release. At work, we're moving toward using annotated tags for our releases so that they are cryptographically signed, contain author and date, and perhaps most importantly, work better with git describe. I was asked to fix the lightweight tags I made for Jifty-DBI releases, which involved a few git incantations I had never used before; hence this post. The basic procedure is:

  1. check out the lightweight tag
  2. delete it locally
  3. create the annotated commit (backdated to the commit it points to)
  4. delete the remote lightweight tag
  5. quickly push the annotated tag

Here's the syntax for each of these commands to upgrade tag 0.64 from lightweight to annotated.

git checkout 0.64
git tag -d 0.64
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -s 0.64 -m '0.64'
git push origin :refs/tags/0.64
git push --tags