如何将 git 分支上的标签移动到不同的提交? [英] How can I move a tag on a git branch to a different commit?
问题描述
我在主分支上创建了一个名为 v0.1
的标签,如下所示:
I created a tag on the master branch called v0.1
like this:
git tag -a v0.1
但后来我意识到我仍然需要将一些更改合并到 0.1 版的 master 中,所以我这样做了.但是现在我的 v0.1
标签卡在(调用便利贴类比)错误的提交上.我希望它停留在 master 上的最近一次提交上,而是停留在 master 上的第二次最近提交上.
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.
如何将其移动到 master 上的最新提交?
How can I move it to the most recent commit on master?
推荐答案
使用 -f
选项git 标签
:
Use the -f
option to git tag
:
-f
--force
Replace an existing tag with the given name (instead of failing)
您可能希望将 -f
与 -a
结合使用来强制创建带注释的标签,而不是未带注释的标签.
You probably want to use -f
in conjunction with -a
to force-create an annotated tag instead of a non-annotated one.
在推送之前删除任何遥控器上的标签
Delete the tag on any remote before you push
git push origin :refs/tags/<tagname>
替换标签以引用最近的提交
Replace the tag to reference the most recent commit
git tag -fa <tagname>
将标签推送到远程源
Push the tag to the remote origin
git push origin master --tags
这篇关于如何将 git 分支上的标签移动到不同的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!