git 如何删除远程标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5480258/
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
How to delete a remote tag?
提问by markdorison
How do you delete a Git tag that has already been pushed?
如何删除已经推送的 Git 标签?
回答by Adam Franco
You just need to push an 'empty' reference to the remote tag name:
您只需要推送一个对远程标签名称的“空”引用:
git push origin :tagname
Or, more expressively, use the --delete
option (or -d
if your git version is older than 1.8.0):
或者,更明确地使用该--delete
选项(或者-d
如果您的 git 版本早于 1.8.0):
git push --delete origin tagname
Note that git has tag namespace and branch namespace so you may use the same name for a branch and for a tag. If you want to make sure that you cannot accidentally remove the branch instead of the tag, you can specify full ref which will never delete a branch:
请注意,git 具有标记命名空间和分支命名空间,因此您可以对分支和标记使用相同的名称。如果您想确保不会意外删除分支而不是标签,您可以指定永远不会删除分支的完整引用:
git push origin :refs/tags/tagname
If you also need to delete the local tag, use:
如果还需要删除本地标签,请使用:
git tag --delete tagname
Background
背景
Pushing a branch, tag, or other ref to a remote repository involves specifying "which repo, what source, what destination?"
将分支、标签或其他引用推送到远程存储库涉及指定“哪个存储库、哪个源、哪个目的地?”
git push remote-repo source-ref:destination-ref
A real world example where you push your master branch to the origin's master branch is:
将主分支推送到源的主分支的真实示例是:
git push origin refs/heads/master:refs/heads/master
Which because of default paths, can be shortened to:
由于默认路径,可以缩短为:
git push origin master:master
Tags work the same way:
标签的工作方式相同:
git push origin refs/tags/release-1.0:refs/tags/release-1.0
Which can also be shortened to:
也可以简写为:
git push origin release-1.0:release-1.0
By omitting the source ref (the part before the colon), you push 'nothing' to the destination, deleting the ref on the remote end.
通过省略源引用(冒号之前的部分),您将“无”推送到目标,删除远程端的引用。
回答by quexer
A more straightforward way is
更直接的方法是
git push --delete origin YOUR_TAG_NAME
IMO prefixing colon syntax is a little bit odd in this situation
在这种情况下,IMO 前缀冒号语法有点奇怪
回答by Alex Dean
If you have a remote tag v0.1.0
to delete, and your remote is origin
, then simply:
如果您v0.1.0
要删除一个远程标签,并且您的远程是origin
,那么只需:
git push origin :refs/tags/v0.1.0
If you also need to delete the tag locally:
如果还需要在本地删除标签:
git tag -d v0.1.0
See Adam Franco's answerfor an explanation of Git's unusual :
syntax for deletion.
有关Git 异常删除语法的解释,请参阅Adam Franco的回答:
。
回答by Siddhartha Mukherjee
Delete all local tags and get the list of remote tags:
删除所有本地标签并获取远程标签列表:
git tag -l | xargs git tag -d
git fetch
Remove all remote tags
删除所有远程标签
git tag -l | xargs -n 1 git push --delete origin
Clean up local tags
清理本地标签
git tag -l | xargs git tag -d
回答by Andrea
To remove the tag from the remote repository:
要从远程存储库中删除标签:
git push --delete origin TAGNAME
You may also want to delete the tag locally:
您可能还想在本地删除标签:
git tag -d TAGNAME
回答by Mahmoud Zalt
From your terminal, do this:
从您的终端,执行以下操作:
git fetch
git tags
git tag -d {tag-name}
git push origin :refs/tags/{tag-name}
Now go to Github.com and refresh, they disappear.
现在去 Github.com 并刷新,它们消失了。
回答by kokabi
回答by Lyes CHIOUKH
回答by Alex Vazquez Fente
Just notice that, if you have a remote branch named as a remote tag, these commands are ambiguous:
请注意,如果您有一个名为远程标签的远程分支,这些命令是不明确的:
git push origin :tagname
git push --delete origin tagname
So you must use this command to delete the tag:
所以你必须使用这个命令来删除标签:
git push origin :refs/tags/<tag>
and this one to delete the branch:
而这个删除分支:
git push origin :refs/heads/<branch>
If not, you would get an error like this:
如果没有,你会得到这样的错误:
error: dst refspec <tagname> matches more than one.
error: failed to push some refs to '<repo>'
回答by TonyH
Up to 100x faster method for thousands of remote tags
数千个远程标签的方法最多可提高 100 倍
After reading through these answers while needing to delete over 11,000 tags, I learned these methods relying or xargs
take far too long, unless you have hours to burn.
在需要删除超过 11,000 个标签的同时阅读这些答案后,我了解到这些方法依赖或xargs
花费的时间太长,除非您有数小时的时间。
Struggling, I found two muchfaster ways. For both, start with git tag
or git ls-remote --tags
to make a list of tags you want to delete on the remote. In the examples below you can omit or replace sorting_proccessing_etc
with any grep
ing, sort
ing, tail
ing or head
ing you want (e.g.grep -P "my_regex" | sort | head -n -200
etc) :
挣扎,我发现了两个多更快的方法。对于两者,从git tag
或git ls-remote --tags
开始制作要在遥控器上删除的标签列表。在下面的示例中,您可以省略或替换sorting_proccessing_etc
为您想要的任何grep
ing、sort
ing、tail
ing 或head
ing(例如grep -P "my_regex" | sort | head -n -200
等):
This first method is by far the fastest, maybe 20 to 100 timesfaster than using xargs
, and works with a least several thousandtags at a time.
第一种方法是迄今为止最快的,可能比使用 快20 到 100 倍xargs
,并且一次至少处理数千个标签。
git push origin $(< git tag | sorting_processing_etc \
| sed -e 's/^/:/' | paste -sd " ") #note exclude "<" for zsh
How does this work?
The normal, line-separated list of tags is converted to a single line of space-separated tags, each prepended with :
so . . .
这是如何运作的?正常的、以行分隔的标签列表被转换为一行以空格分隔的标签,每个标签都以:
so开头。. .
tag1 becomes
tag2 ======> :tag1 :tag2 :tag3
tag3
Using git push
with this format tag pushes nothinginto each remote ref, erasing it (the normal format for pushing this way is local_ref_path:remote_ref_path
).
使用git push
此格式标签不会将任何内容推送到每个远程引用中,将其擦除(以这种方式推送的正常格式是local_ref_path:remote_ref_path
)。
Method two is broken out as a separate answer elsewhere on this same page
方法二在同一页面的其他地方作为单独的答案分解
After both of these methods, you'll probably want to delete your local tags too.
This is much faster so we can go back to using xargs
and git tag -d
, which is sufficient.
在这两种方法之后,您可能也想删除您的本地标签。这要快得多,所以我们可以回到使用xargs
and git tag -d
,这就足够了。
git tag | sorting_processing_etc | xargs -L 1 git tag -d
OR similar to the remote delete:
或类似于远程删除:
git tag -d $(< git tag | sorting_processing_etc | paste -sd " ")