创建一个带有特定标签名称、标签日期的带注释的 git-tag

时间:2021-03-26 14:26:19

标签: git git-tag

如何使用特定的 annotatedgit-tag 创建 tagger-name tagged-date

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

来自另一个 stackoverflow 问题:

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>

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

2 个答案:

答案 0 :(得分:2)

带注释的标签与提交非常相似,因此 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@stackoverflow.com \
      tag -a 1234abc

答案 1 :(得分:1)

简单且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>