我们的Git存储库中有几个带注释的标记。旧的标记具有虚假的消息,我们希望将其更新为新样式。

% git tag -n1
v1.0 message
v1.1 message
v1.2 message
v2.0 Version 2.0 built on 15 October 2011.

在这个例子中,我们想让v1。X消息看起来像v2.0消息。我们该怎么做呢?


当前回答

使用上面的答案(特别是Sungam的答案),这是.gitconfig的别名一行程序。替换现有标签并保留提交日期。

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

改进吗?

其他回答

git tag <tag name> <tag name>^{} -f -m "<new message>"

这将创建一个具有相同名称的新标记(通过覆盖原始标记)。

要更新一个复杂的消息,只需用-a指定带注释的标记选项或用-s指定带符号的标记选项:

git tag <tag name> <tag name>^{} -f -a

这将打开一个包含旧标记消息内容的编辑器。

我们想要得到v1。X消息看起来像v2.0消息

在Git 2.17(2018年第二季度)中,将有一种替代方法来创建一个新的标记,使用Git标签<标签名> <标签名> -f -m" <新消息>",因为“Git标签”学习了一个显式的“——edit”选项,允许通过“-m”和“-f”给出的消息被进一步编辑。

参见Nicolas morey - chaisemmartin (nmorey)的commit 9eed6e4(2018年2月6日)。 (由Junio C Hamano - gitster -在commit 05d290e, 2018年3月6日合并)

标签:添加——编辑选项 添加一个——edit选项,允许修改-m或-F提供的消息,就像git commit——edit所做的一样。

使用上面的答案(特别是Sungam的答案),这是.gitconfig的别名一行程序。替换现有标签并保留提交日期。

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

改进吗?

您将不得不再次标记,使用-f力标志。

git tag v1.0 -f -m "actual message"