从 Git 存储库中删除所有标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19542301/
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
Delete all tags from a Git repository
提问by Ionic? Biz?u
I want to delete all the tags from a Git repository. How can I do that?
我想从 Git 存储库中删除所有标签。我怎样才能做到这一点?
Using git tag -d tagname
delete the tag tagname
locally, and using git push --tags
I update the tags on the git provider.
使用git tag -d tagname
在tagname
本地删除标签,并使用git push --tags
我更新 git 提供程序上的标签。
I tried:
我试过:
git tag -d *
But I see that *
means the files from the current directory.
但我看到这*
意味着来自当前目录的文件。
$ git tag -d *
error: tag 'file1' not found.
error: tag 'file2' not found.
...
Consider I have a lot of tags, and I want to delete them, all.
考虑到我有很多标签,我想全部删除它们。
回答by Florian Margaine
git tag | xargs git tag -d
Simply use the Linux philosophy where you pipe everything. On Windows use git bash with the same command.
只需使用 Linux 哲学来管理一切。在 Windows 上使用 git bash 和相同的命令。
回答by karlingen
To delete remote tags (before deleting local tags) simply do:
要删除远程标签(在删除本地标签之前),只需执行以下操作:
git tag -l | xargs -n 1 git push --delete origin
and then delete the local copies:
然后删除本地副本:
git tag | xargs git tag -d
回答by Richard A Quadling
It may be more efficient to push delete all the tags in one command. Especially if you have several hundred.
在一个命令中推送删除所有标签可能更有效。特别是如果你有几百个。
In a suitable non-windows shell, delete all remote tags:
在合适的非 windows shell 中,删除所有远程标签:
git tag | xargs -L 1 | xargs git push origin --delete
Then delete all local tags:
然后删除所有本地标签:
git tag | xargs -L 1 | xargs git tag --delete
This should be OK as long as you don't have a '
in your tag names. For that, the following commands should be OK.
只要'
您的标签名称中没有 a ,这应该没问题。为此,以下命令应该没问题。
git tag | xargs -I{} echo '"{}"' | tr \n \0 | xargs --null git push origin --delete
git tag | xargs -I{} echo '"{}"' | tr \n \0 | xargs --null git tag --delete
Other ways of taking a list of lines, wrapping them in quotes, making them a single line and then passing that line to a command probably exist. Considering this is the ultimate cat skinning environment and all.
获取行列表,将它们用引号括起来,使它们成为一行然后将该行传递给命令的其他方法可能存在。考虑到这是最终的猫剥皮环境等等。
回答by Yong Choi
Adding to Stefan's answer which was missing how to delete tags from remote. For windows powershell you can run this to delete the remote tags first followed by the local tags.
添加到 Stefan 的答案中,该答案缺少如何从远程删除标签。对于 windows powershell,您可以运行此命令先删除远程标签,然后再删除本地标签。
git tag | foreach-object -process { git push origin --delete $_ }
git tag | foreach-object -process { git tag -d $_ }
回答by Stefan Domnanovits
For Windows users using PowerShell:
对于使用 PowerShell 的 Windows 用户:
git tag | foreach-object -process { git tag -d $_ }
This deletes all tags returned by git tag
by executing git tag -d
for each line returned.
这将删除git tag
通过git tag -d
对返回的每一行执行而返回的所有标记。
回答by Valtoni Boaventura
If you don't have the tags in your local repo, you can delete remote tags without have to take it to your local repo.
如果您的本地仓库中没有标签,您可以删除远程标签,而不必将其带到您的本地仓库。
git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete
Don't forget to replace "origin" to your remote handler name.
不要忘记将“origin”替换为您的远程处理程序名称。
回答by Gigi2m02
For windows users:
对于 Windows 用户:
This deletes all Local Tags by running git tag and feeding that list to git tag -d:
这通过运行 git tag 并将该列表提供给 git tag -d 来删除所有本地标签:
FOR /f "tokens=*" %a in ('git tag') DO git tag -d %a
(Found on: https://gist.github.com/RandomArray/fdaa427878952d9768b0)
(发现于:https: //gist.github.com/RandomArray/fdaa427878952d9768b0)
回答by ViZeke
You can also use:
您还可以使用:
git tag -d $(git tag)
回答by DarkWiiPlayer
Since all these options only work in linux, here's the windows equivalent for anybody having to deal with that:
由于所有这些选项仅适用于 linux,因此对于必须处理该问题的任何人来说,这里是 Windows 等效项:
FOR /F usebackq %t IN (`git tag`) DO @git tag --delete %t
回答by Brady Huang
I have to delete the tags with prefix
我必须删除带有前缀的标签
for example, I have to delete the tags v0.0.1, v0.0.2, v0.0.3, v0.0.4, v0.0.5
例如,我必须删除标签 v0.0.1、v0.0.2、v0.0.3、v0.0.4、v0.0.5
git tag -d $(git tag -l "v0.0.*")
To list all the tags with prefix
列出所有带前缀的标签
git tag -l "v0.0.*"
To delete the tags
删除标签
git tag -d $tag_names
That's how the first statement works
这就是第一个语句的工作方式