How to re-tag something in git

I make mistakes. One of the more annoying ones I make, is to push a release with the wrong tag, causing all sorts of issues. Here's how to re-tag things in git:

Use git reflog to find the thing you want to re-tag (likely one of the most recent ones) - jot down the number (e.g. a2a6ebea2)

Use  git describe a2a6ebea2 to double check that it points to your misconfigured release (e.g. releases/product name/version number)

Get your tag names with (git for-each-ref --sort='-taggerdate' --format='%(tag),%(taggerdate:iso8601),%(refname),' "refs/tags/releases/**")

Delete the erroneous tag with git tag --delete tag name

Create a new tag with git tag --annotate "new tag name" a2a6ebea2 --message "Version NNNN"

Push the deletion of the old tag with git push origin :refs/tags/old tag name

Push the creation of the new tag with git push --tags

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints