你如何重命名一个Git标签? [英] How do you rename a Git tag?

查看:616
本文介绍了你如何重命名一个Git标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我正在浏览一个项目的日志,并意识到我前一段时间发现了一个标签名称。有什么方法可以重命名标签吗?谷歌还没有发现任何有用的东西。



我意识到我可以检出标签的版本并制作新的标签,我甚至尝试过。但是,这似乎创建了一个不太正确的标签对象。举个例子,

  git tag -l 

将其与其他所有标签相比按顺序排列。我不知道这是否意义重大,但它让我相信新的标签对象并不是我想要的。我可以忍受这一点,因为我真的只关心标签名称与文档相匹配,但我宁愿这样做正确,假设有一个正确的方法来做到这一点。

>:

  git tag new old 
git tag -d old
git push origin:refs / tags / old
git push --tags

push命令中的冒号将标记从远程存储库。如果你不这样做,git会在你的机器上创建旧的标签。



最后,确保其他用户删除已删除的标签。请告诉他们(同事)运行以下命令:

  git pull --prune --tags 


Today I was looking through the logs for a project and realized that I fat fingered a tag name some time ago. Is there some way to rename the tag? Google hasn't turned up anything useful.

I realize I could check out the tagged version and make a new tag, I even tried that. But that seems to create a tag object that isn't quite right. For one,

git tag -l

lists it out of order relative to all of the other tags. I have no idea if that's significant, but it leads me to believe that the new tag object isn't quite what I want. I can live with that, because I really only care that the tag name matches the documentation, but I'd rather do it "right", assuming there is a right way to do this.

解决方案

Here is how I rename a tag old to new:

git tag new old
git tag -d old
git push origin :refs/tags/old
git push --tags

The colon in the push command removes the tag from the remote repository. If you don't do this, git will create the old tag on your machine when you pull.

Finally, make sure that the other users remove the deleted tag. Please tell them(co-workers) to run the following command:

git pull --prune --tags

这篇关于你如何重命名一个Git标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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