用 Git 替换远程标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20076233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replace remote tag with Git
提问by azmeuk
I have some tags on my "origin" repository. Then I realized I needed to add some changes on one of the tags, and push them back on my repository. Is there a way I can push an existing tag to the repository in one time, or should I delete the tag before ?
我的“来源”存储库上有一些标签。然后我意识到我需要在其中一个标签上添加一些更改,并将它们推送回我的存储库。有没有一种方法可以一次性将现有标签推送到存储库,还是应该在此之前删除该标签?
回答by Bijendra
This should not be the practice, though you can delete the tag and push the change to the remote repo.
这不应该是惯例,尽管您可以删除标签并将更改推送到远程存储库。
git tag -d tag1
git push origin :refs/tags/tag1
回答by Exequiel Barrirero
So if you need to move a tag (eg: "v0.5") on a git branch (eg: "master") to a different commit, probably a newer one, then you can use the -f
option to git tag
:
因此,如果您需要将git 分支(例如:“master ”)上的标签(例如:"v0.5")移动到不同的提交,可能是更新的提交,那么您可以使用以下选项:-f
git tag
-f
--force
Replace an existing tag with the given name (instead of failing)
You probably want to use -f
in conjunction with -a
to force-create an annotated tag instead of a non-annotated one.
您可能希望-f
结合使用-a
来强制创建带注释的标签而不是未带注释的标签。
Example
例子
Delete the tag on any remote before you push
git push origin :refs/tags/<tagname>
or for our example:
$ git push origin master :refs/tags/v0.5 To [email protected]:org_name/repo_name.git - [deleted] v0.5
Replace the tag to reference the most recent commit (using -f will save as the
git tag -d <tagname>
local tag deletion step).git tag -fa <tagname>
or for our example:
$ git tag -fa "v0.5" -m "version 0.5" Updated tag 'v0.5' (was f55c93f)
Push the tag to the remote origin
git push origin --tags
or for our example:
$ git push origin master --tags Counting objects: 1, done. Writing objects: 100% (1/1), 196 bytes | 0 bytes/s, done. Total 1 (delta 0), reused 0 (delta 0) To [email protected]:org_name/repo_name.git * [new tag] v0.5 -> v0.5
在推送之前删除任何遥控器上的标签
git push origin :refs/tags/<tagname>
或者对于我们的例子:
$ git push origin master :refs/tags/v0.5 To [email protected]:org_name/repo_name.git - [deleted] v0.5
替换标签以引用最近的提交(使用 -f 将保存为
git tag -d <tagname>
本地标签删除步骤)。git tag -fa <tagname>
或者对于我们的例子:
$ git tag -fa "v0.5" -m "version 0.5" Updated tag 'v0.5' (was f55c93f)
将标签推送到远程源
git push origin --tags
或者对于我们的例子:
$ git push origin master --tags Counting objects: 1, done. Writing objects: 100% (1/1), 196 bytes | 0 bytes/s, done. Total 1 (delta 0), reused 0 (delta 0) To [email protected]:org_name/repo_name.git * [new tag] v0.5 -> v0.5
回答by CDub
I'm not sure I understand your question, but it sounds like it would be simplest to delete the tag, push your change, then re-add the tag...
我不确定我是否理解您的问题,但听起来最简单的是删除标签,推送您的更改,然后重新添加标签......