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

git tag -a v0.1

但后来我意识到,在0.1版的master中还需要合并一些更改,所以我就这么做了。但是现在我的v0.1标签被粘在了错误的提交上(引用便利贴的类比)。我希望它卡在主节点上的最近提交上,但它却卡在主节点上的第二个最近提交上。

我如何移动它到最近提交的主?


当前回答

还有一种方法:

移动标签在远程回购。(如有需要,请更换HEAD。)

$ git push --force origin HEAD:refs/tags/v0.0.1.2

取回更改。

$ git fetch --tags

其他回答

本地删除:

git tag -d v0.1  

远程移除:

git push origin --delete v0.1

然后在本地重新添加,并将v0.1推送到最近的提交:

git tag -a v0.1
git push origin --tags

使用git标记-d <tagname>删除它,然后在正确的提交时重新创建它。

对git标签使用-f选项:

-f
--force

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

您可能希望将-f与-a结合使用,以强制创建一个带注释的标记,而不是无注释的标记。

例子

在按之前,请删除任何遥控器上的标签 Git push origin:refs/tags/<tagname> 替换标记以引用最近的提交 Git标签-fa <tagname> 将标签推到远端原点 Git push origin master——tags

更准确地说,你必须强制添加标签,然后用option——tags和-f push:

git tag -f -a <tagname>
git push -f --tags

总结一下,如果你的远程名为origin并且你正在主分支上工作:

git tag -d <tagname>                  # delete the old tag locally
git push origin :refs/tags/<tagname>  # delete the old tag remotely
git tag <tagname> <commitId>          # make a new tag locally
git push origin <tagname>             # push the new local tag to the remote 

描述:

第1行删除本地env中的标记。 第2行删除远程环境中的标记。 第3行将标记添加到不同的提交 第4行将更改推到远程

您还可以将第4行更改为git push origin——tags,以将所有本地标记更改/更新推到远程repo。

上面的答案是基于@eedeep的问题内容,以及Stuart Golodetz、Greg Hewgill和@ben-hocking的回答,以及他们的回答下面的评论,以及@NateS在我的回答下面的原始评论。