更改 git 标签的日期(或基于它的 GitHub Release) [英] Change date of git tag (or GitHub Release based on it)

查看:23
本文介绍了更改 git 标签的日期(或基于它的 GitHub Release)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过向各种提交添加标签来将

解决方案

警告:这将不会保留带注释标签的标签消息.

总结

对于每个需要更改的标签:

  1. 及时回到代表标签的提交
  2. 删除标签(本地和远程)
    • 这会将你在 GitHub 上的Release"变成你以后可以删除的草稿.
  3. 使用将日期设置为提交日期的魔术调用重新添加同名标签.
  4. 将具有固定日期的新标签推送回 GitHub.
  5. 转到 GitHub,删除所有现在草稿的版本,然后使用新标签重新创建新版本

在代码中:

# Fixing tag named '1.0.1'git checkout 1.0.1 # 转到关联的提交git tag -d 1.0.1 # 本地删除标签git push origin :refs/tags/1.0.1 # 将此删除推送到 GitHub# 创建标签,日期来自当前头部GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a 1.0.1 -m"v1.0.1"git push --tags # 将固定的标签发送到 GitHub

详情

根据 如何在 Git 中标记:

<块引用>

如果您忘记标记发布或版本提升,您始终可以像这样追溯标记它:

git checkout SHA1_OF_PAST_COMMITgit tag -m"追溯标记版本 1.5" v1.5

虽然这完全可用,但它的效果是使您的标签不按时间顺序排列,这可能会与寻找最新"标签的构建系统发生冲突.但不要害怕.Linus 想到了一切:

# 这会将你移动到历史上存在提交的点git checkout SHA1_OF_PAST_COMMIT# 此命令为您提供当前提交的日期时间git show --format=%aD |头-1# 这会暂时将 git tag 的时钟设置回你从上面复制/粘贴的日期GIT_COMMITTER_DATE="Thu Nov 11 12:21:57 2010 -0800" git tag -a 0.9.33 -m"追溯标记版本 0.9.33"# 将两者结合...GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a 0.9.33 -m"追溯标记版本 0.9.33"

但是,如果你已经添加了标签,你不能使用上面的 git tag -f existingtag 否则当你尝试合并时 git 会报错:

Rammy:docubot phrogz$ git push --tags至 git@github.com:Phrogz/docubot.git![拒绝] 1.0.1 ->1.0.1(已经存在)错误:未能将一些参考资料推送到 'git@github.com:Phrogz/docubot.git'提示:更新被拒绝,因为标签已经存在于遥控器中.

相反,您必须在本地删除标签:

git tag -d 1.0.1

远程推送删除:

git push origin :refs/tags/1.0.1

在 GitHub 上,重新加载版本(该版本现已被标记为草稿")并删除草稿.

现在,根据上面的说明添加回溯标签,最后将生成的标签推送到GitHub:

git push --tags

然后再去重新添加 GitHub Release 信息.

I'm adding Releases to my projects on GitHub by adding tags to various commits in the Main branch.

In one of my projects I did not add the tags to the commits in chronological order. (I found obvious commits and tagged them, and then I found less obvious, older commits and tagged them.)

Now GitHub is showing v1.0.1 as current, with v0.7.0 preceding it, and v1.1.2 preceding that.

It appears to use the date on a tag's creation as the Release date instead of the commit that is being tagged. How can I edit my tags so that their dates are the same as the commit they are tagging?

解决方案

WARNING: This will not preserve tag messages for annotated tags.

Summary

For each tag that needs to be changed:

  1. Go back in time to the commit representing the tag
  2. Delete the tag (locally and remotely)
    • This will turn your "Release" on GitHub into a Draft that you can later delete.
  3. Re-add the same-named tag using a magic invocation that sets its date to the date of the commit.
  4. Push the new tags with fixed dates back up to GitHub.
  5. Go to GitHub, delete any now-draft releases, and re-create new releases from the new tags

In code:

# Fixing tag named '1.0.1'
git checkout 1.0.1               # Go to the associated commit
git tag -d 1.0.1                 # Locally delete the tag
git push origin :refs/tags/1.0.1 # Push this deletion up to GitHub

# Create the tag, with a date derived from the current head
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a 1.0.1 -m"v1.0.1"

git push --tags                  # Send the fixed tags to GitHub

Details

According to How to Tag in Git:

If you forget to tag a release or version bump, you can always tag it retroactively like so:

git checkout SHA1_OF_PAST_COMMIT
git tag -m"Retroactively tagging version 1.5" v1.5

And while that's perfectly usable, it has the effect of putting your tags out of chronological order which can screw with build systems that look for the "latest" tag. But have no fear. Linus thought of everything:

# This moves you to the point in history where the commit exists
git checkout SHA1_OF_PAST_COMMIT

# This command gives you the datetime of the commit you're standing on
git show --format=%aD  | head -1

# And this temporarily sets git tag's clock back to the date you copy/pasted in from above
GIT_COMMITTER_DATE="Thu Nov 11 12:21:57 2010 -0800" git tag -a 0.9.33 -m"Retroactively tagging version 0.9.33"

# Combining the two...
GIT_COMMITTER_DATE="$(git show --format=%aD  | head -1)" git tag -a 0.9.33 -m"Retroactively tagging version 0.9.33"

However, if you have already added the tag, you cannot use the above with git tag -f existingtag or else git will complain when you try to merge:

Rammy:docubot phrogz$ git push --tags
To git@github.com:Phrogz/docubot.git
 ! [rejected]        1.0.1 -> 1.0.1 (already exists)
error: failed to push some refs to 'git@github.com:Phrogz/docubot.git'
hint: Updates were rejected because the tag already exists in the remote.

Instead, you must remove the tag locally:

git tag -d 1.0.1

Push that deletion remotely:

git push origin :refs/tags/1.0.1

On GitHub, reload Releases—the release has now been marked as a "Draft"—and remove the draft.

Now, add the backdated tag based on the instructions above, and finally push the resulting tag to GitHub:

git push --tags

and then go and re-add the GitHub Release information again.

这篇关于更改 git 标签的日期(或基于它的 GitHub Release)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆