当标签已存在于远程时​​,Git 强制推送标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25815631/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:27:36  来源:igfitidea点击:

Git force push tag when the tag already exists on remote

gitgit-tag

提问by user3606175

I have a tag already pushed onto the remote, and when another user creates the same tag and tries to push, push will fail because tag already exists on the remote.

我有一个标签已经推送到遥控器上,当另一个用户创建相同的标签并尝试推送时,推送将失败,因为标签已经存在于遥控器上。

But I thought if I do --f force tag push, it should be work. But that is not what I see.

但我想如果我做 --f force tag push,它应该是有效的。但这不是我所看到的。

I think I have to do this.

我想我必须这样做。

 Create tag
 Push tag -> If push fails -> Delete tag on remote
                           -> push tag again.

Is this correct? Isnt force push tag supposed to take care of this?

这样对吗?强制推送标签不应该解决这个问题吗?

I am using annotated tags with

我正在使用带注释的标签

 git -a v1.0 -f -m "message"

回答by user3606175

In my case, remote was rejecting an force push when the tag already exists.

就我而言,当标签已经存在时,远程拒绝强制推送。

So, when the push was rejected, I did

所以,当推送被拒绝时,我做了

git push --delete origin tagname 

and pushed the new tag.

并推送新标签。

Please see Torek's comment to my question. There is a case when remote can reject the delete too.

请参阅 Torek 对我的问题的评论。有一种情况,远程也可以拒绝删除。

回答by David Dekanozishvili

This will force push all the tags and overwrite the existing ones.

这将强制推送所有标签并覆盖现有标签。

git push -f --tags

回答by Yates Zhou

Firstly, delete that tag you want to replace in remote:

首先,删除要在远程替换的标签:

git push origin --delete <tag-name>

then push your tag to remote:

然后将您的标签推送到远程:

git push --tags