Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
668 views
in Technique[技术] by (71.8m points)

git - 如何重命名Git标签?(How do you rename a Git tag?)

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.

(Google并未提供任何有用的信息。)

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.

(我可以忍受,因为我真的只在乎标记名称是否与文档匹配,但是我宁愿“正确”地进行操作,前提是有正确的方法。)

  ask by Brandon Fosdick translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is how I rename a tag old to new :

(这是我将old标签重命名为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.

(push命令中的冒号将从远程存储库中删除标记。)

If you don't do this, Git will create the old tag on your machine when you pull.

(如果您不这样做,当您拉时,Git将在您的机器上创建旧标签。)

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

Note that if you are changing an annotated tag , you need ensure that the new tag name is referencing the underlying commit and not the old annotated tag object that you're about to delete.

(请注意, 如果要更改带注释的标记 ,则需要确保新标记名称引用的是基础提交,而不是要删除的旧带注释的标记对象。)

Therefore, use git tag -a new old^{} instead of git tag new old (this is because annotated tags are objects while lightweight tags are not, more info in this answer ).

(因此,请使用git tag -a new old^{}代替git tag new old (这是因为带注释的标签是对象,而轻量级的标签不是对象, 有关此信息,请参阅 )。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...