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.
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
The original question was how to rename a tag, which is easy: first create NEW as an alias of OLD: git tag NEW OLD
then delete OLD: git tag -d OLD
.
The quote regarding "the git way" and (in)sanity is offbase because it's talking about preserving a tag name but making it refer to a different repo state.
In addition to the other answers:
First you need to build an alias of the old tag name:
git tag new_tag_name old_tag_name
Edit: As this answer points out, you should take care to point to the correct (original) commit:
git tag new old^{}
Then you need to delete the old one locally:
git tag -d old_tag_name
Then delete the tag on you remote location(s):
# Check your remote sources:
git remote -v
# The argument (3rd) is your remote location,
# the one you can see with `git remote`. In this example: `origin`
git push origin :refs/tags/old_tag_name
Finally you need to add your new tag to the remote location. Until you have done this, the new tag(s) will not be added:
git push origin --tags
Iterate this for every remote location.
Be aware, of the implications that a Git Tag change has to consumers of a package!
链接地址: http://www.djcxy.com/p/5720.html上一篇: 从GitHub下载单个文件
下一篇: 你如何重命名一个Git标签?