创建带有特定标记器名称、标记日期的带注释的 git 标记

Create an annotated git-tag with a particular tagger-name, tagged-date

如何创建具有特定 tagger-nametagged-dateannotated git-tag

docs如何使它正确没有这样的信息。

来自另一个 Whosebug 问题:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git tag <tag-name> [commit]
git push origin <tag-name>

我必须重新定义全局配置设置 - 这显然不是一个好方法

带注释的标签与提交非常相似,因此 git commit 的方法适用于 git tag -a

  • 要指定日期,请使用 GIT_COMMITTER_DATEGIT_AUTHOR_DATE 环境变量。
  • 要临时(仅针对此单个命令)更改 git 配置,请使用 git -c config_key=config.value

所以你可以执行的命令是:

GIT_COMMITTER_DATE="1970-01-01T00:00:00Z" \
GIT_AUTHOR_DATE="1970-01-01T00:00:00Z" \
  git -c user.name='Jeff Atwood' \
      -c user.email=atwood@whosebug.com \
      tag -a 1234abc

简单且 CORRECT 的解决方案是:

$ git mktag <tag-file >output

标签文件:

object <HASH>  # hash of the commit we are want to set tag to
type commit
tag <NAME>  # name of the tag
tagger Bob Dylan <bob.dylan@boby.com> 1484015966 +0000

Message

输出:

<HASH>  # hash of the created tag

之后:

$ git update-ref refs/tags/<NAME of the created tag> <the HASH from output file>