如何将git分支上的标签移动到其他提交? [英] How can I move a tag on a git branch to a different commit?

查看:681
本文介绍了如何将git分支上的标签移动到其他提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  git tag -a v0.1 

但我意识到还有一些变化我需要合并到版本0.1的主版本中,所以我这样做了。但是现在我的 v0.1 标签被卡住了(以便调用便条纸类比)错误的提交。我希望它停留在master上最近的提交上,但是它仍然停留在master上第二次提交的提交中。



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

解决方案

使用 -f 选项 git标记

  -f 
--force

用给定名称替换现有标签(而不是失败)

您可能希望将 -f -a 强制创建一个带注释的标签,而不是一个没有注释的标签。

示例


$ b


  1. 在您推送前删除任何遥控器上的标签

      git push origin:refs / tags /< tagname> 


  2. 将标记替换为引用最近的提交

      git tag -fa< tagname> 


  3. 将标签推送至远程来源

      git push origin master --tags 



I created a tag on the master branch called v0.1 like this:

git tag -a v0.1

But then I realized there were still some changes I needed to merge into master for release 0.1, so I did that. But now my v0.1 tag is stuck on (to invoke the post-it note analogy) the wrong commit. I want it to be stuck on the most recent commit on master, but instead it is stuck on the second most recent commit on master.

How can I move it to the most recent commit on master?

解决方案

Use the -f option to git tag:

-f
--force

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

You probably want to use -f in conjunction with -a to force-create an annotated tag instead of a non-annotated one.

Example

  1. Delete the tag on any remote before you push

    git push origin :refs/tags/<tagname>
    

  2. Replace the tag to reference the most recent commit

    git tag -fa <tagname>
    

  3. Push the tag to the remote origin

    git push origin master --tags
    

这篇关于如何将git分支上的标签移动到其他提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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