git - 如何将 git 分支上的标签移动到不同的提交?

标签 git git-tag

我在主分支上创建了一个名为 v0.1 的标签,如下所示:

git tag -a v0.1

但后来我意识到我仍然需要将一些更改 merge 到 0.1 版本的 master 中,所以我这样做了。但是现在我的 v0.1 标记卡在了错误的提交上(调用便利贴类比)。我希望它停留在 master 上最近的提交上,但它却停留在 master 上的第二个最近提交上。

如何将它移动到 master 上的最新提交?

最佳答案

使用 -f 选项来 git tag :

-f
--force

    Replace an existing tag with the given name (instead of failing)

您可能希望结合使用 -f-a 来强制创建带注释的标签,而不是非带注释的标签。

例子

  1. 在推送之前删除任何 Remote 上的标签

    git push origin :refs/tags/<tagname>
    
  2. 替换标签以引用最近的提交

    git tag -fa <tagname>
    
  3. 将标签推送到远端

    git push origin master --tags
    

关于git - 如何将 git 分支上的标签移动到不同的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8044583/

相关文章:

Git 将两个相似的存储库 merge 为一个(都增加了冲突)

git - 如何将 Bitbucket post-commit Hook shell 脚本正确转换为 Powershell 脚本?

git - 从私有(private) GitHub 存储库 checkout 标签

Git 标签 - checkout 问题

git - 是否有一种久经考验的方法来创建一个包含所有已知推荐忽略的 .gitignore ?

git - GitLab 中不显示重音

git - 为什么 git status 和 git show 不一致?

git - 如何删除链接存储库中的 git 远程标签?

Github分支,标签: How to get a specific release of a code?

git - Github 页面上的 Powerpoint 演示文稿