How do I edit an existing tag message in git?

2020-01-25 03:33发布

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 git-tag
8条回答
Bombasti
2楼-- · 2020-01-25 04:01

Using the answers above, this is my alias one-liner for .gitconfig. Replaces existing tag and preserves the commit date.

[alias]
    tm = "!sh -c 'f() { export GIT_COMMITTER_DATE=$(git log -1 --format=%ci $0); git tag -f -a $0 $0^{}; }; f '"

Improvements?

查看更多
再贱就再见
3楼-- · 2020-01-25 04:09

@Andy 's solution

git tag <tag-name> <tag-name> -f -a

is wrong. After it, with

git show

command, we will see stack tags with same name.

It add a new tag with same tag name and new message at commit <tag-name>. But it don't remove old tag. It's a special case of this command:

git tag [<commit> | <old-tag>] <tag-name>

But just <old-tag> is same with <tag-name>.


Correct solution is simple, just update tag is OK.

git tag <tag-name> -f -a

Remember, only ONE here.

If we want change tag, which isn't HEAD, we need an extra <commit> argument.

git tag <commit> <tag-name> -f -a
查看更多
登录 后发表回答