We have several annotated tags in our git repository. The older tags have bogus messages that we would like to update to be in our new style.
% git tag -n1
v1.0 message
v1.1 message
v1.2 message
v2.0 Version 2.0 built on 15 October 2011.
In this example, we would like to make v1.x messages look like the v2.0 message. Anyone know how we would do this?
git tag <tag name> <tag name>^{} -f -a
This is an improvement over Andy and Eric Hu's answers. Their answers will create a new tag object that reference the old tag object, where both of them will have the same tag name.
<tag name>^{}
will resolve the tag/reference until it find the first commit hash.To update a complex message, just specify the annotated tag option with
-a
or the signed tag option with-s
:This will open an editor with the contents of your old tag message.
git tag <tag name> <tag name>^{} -f -m "<new message>"
This will create a new tag with the same name (by overwriting the original).
With Git 2.17 (Q2 2018), there will be an alternative to creating a new tag with
git tag <tag name> <tag name> -f -m "<new message>"
, since "git tag
" learned an explicit "--edit
" option that allows the message given via "-m
" and "-F
" to be further edited.See commit 9eed6e4 (06 Feb 2018) by Nicolas Morey-Chaisemartin (
nmorey
).(Merged by Junio C Hamano --
gitster
-- in commit 05d290e, 06 Mar 2018)Add a
--edit
option which allows modifying the messages provided by-m
or-F
, the same waygit commit --edit
does.You will have to tag again, using the
-f
force flag.TL;DR
You can do this by deleting your tag and recreating it while spoofing the date and author:
Whole story:
Building on Sungram's answer (originally proposed as an edit):
1. Accepted answer
This is an improvement over Andy and Eric Hu's answers. Their answers will create a new tag object that references the old tag object and both are going to have the same name.
To illustrate this, consider the following:
2. Sungram's improvement
Using
<tag name>^{}
as the second argument ofgit tag
will instead delete all previous tags with the same name.Consider the continuation of the previous terminal session:
3. Save the date
Lastly, if you want to keep the date of the original tag as the date of the updated tag, use some awk (or similar) magic or just paste the date you want instead. The following is a substitute for the second example (otherwise the original date would be lost due to overriding):
References:
SO: Quick listing objects in git database
SO: Change the committer date of a git tag
Awk: A tutorial and introduction
SO: Filter output by first-token-of-line and extract rest-of-line with awk
SO: How to put bash line comment in a multi-line command
4. DIY
Alternatively to updating the tags, you can just delete them and create them again. As it turns out updating just adds a new tag and makes it point to the old one, or alternatively, just implicitly deletes the old one and creates a new one to point to the same commit anyway.
You can achieve this by issuing:
Here
[optional]
is an optional field;<required>
is a required field. Of course, you can add any flags after thegit tag
command that you normally would.