Renaming git tags results in inconsistency

To reiterate the standard caution whenever someone suggests rewriting history (or in this instance, retagging history) -- if you can avoid it, don't do it.

However, there are times it just isn't worth the long-term pain of an inaccurate (messy) history and the short-term pain is worth it.

If that is the case, the following article gives the steps needed: How to Rename a Tag Already Pushed to a Remote git Repo.

Basic steps are:

git tag new_tag old_tag
git push --tags
git push origin :refs/tags/old_tag
git tag -d old_tag

I've run into the same issue a few minutes ago. None of the answers already presented dealt with the real issue which is getting rid of the message warning: tag 'foo' is really 'bar' here and getting git describe to just list the new name of the tag. This was especially important in my case, as my build system uses git describe to record into the build what sources were used to make the build.

Replicating the Problem

I can replicate the issue by doing this:

$ git tag foo --annotate -m"original message"
$ git tag bar foo
$ git tag -d foo
$ git describe 
warning: tag 'foo' is really 'bar' here
foo

(The --annotate flag above is redundant as -m implies --annotate, but I've included it for emphasis.) I've tried to replicate the problem with a lightweight tag but was not able to do so. So to replicate the issue, an annotation is necessary.

Fixing the Problem

Some of this involves pushing over things that have peen pushed already but I find myself in agreement with David Culp when he says:

However, there are times it just isn't worth the long-term pain of an inaccurate (messy) history and the short-term pain is worth it.

Once you are stuck with the warning: tag 'foo' is really 'bar' here, then you must do:

$ git tag bar bar -m"original message" --force
$ git describe 
bar

Adapt as needed if the message needs changing.

To delete the old tag if it was already pushed:

$ git push origin :refs/tags/foo

To update the new tag if it was already pushed:

$ git push origin refs/tags/bar

Avoiding the Problem

To avoid the problem in the first place you'd have to create bar with:

$ git tag bar foo -m"original message"

Tags:

Git

Git Tag