git 删除多个git远程标签并推送一次

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

Delete multiple git remote tags and push once

gittags

提问by KanwarG

In Git, how can I delete multiple tags before pushing?

在 Git 中,如何在推送之前删除多个标签?

I know how to do it with one tag at a time. Not sure if it's possible to do multiple.

我知道如何一次使用一个标签。不确定是否可以做多个。

回答by zigarn

To delete locally multiple tags: git tag:

在本地删除多个标签:git tag

git tag -d <tagname>...

git tag -d <标签名>...

So simply:

很简单:

git tag -d TAG1 TAG2 TAG3

To delete multiple tags remotely: git push:

远程删除多个标签:git push

git push [-d | --delete] [<repository> [<refspec>...]]

git push [-d | --delete] [<repository> [<refspec>...]]

So simply:

很简单:

git push ${REMOTE_NAME:-origin} --delete TAG1 TAG2 TAG3

TL;DR:

特尔;博士:

git tag -d TAG1 TAG2 TAG3
git push origin -d TAG1 TAG2 TAG3

回答by AechoLiu

It will delete all matching tag patterns.

它将删除所有匹配的标签模式。

//Delete remote:
git push -d origin $(git tag -l "tag_prefix*")

// Delete local:
git tag -d $(git tag -l "tag_prefix*")

// Examples:
git tag -d $(git tag -l "v1.0*")
git push -d origin $(git tag -l "*v3.[2]*-beta*")

回答by Lemtronix

I found an easy way to do this if you have grepand xargsinstalled. I am shamelessly taking this from https://gist.github.com/shsteimer/7257245.

如果您已安装grepxargs安装,我找到了一种简单的方法来执行此操作。我无耻地从https://gist.github.com/shsteimer/7257245拿了这个。

Delete all the remote tags with the pattern your looking for:

使用您要查找的模式删除所有远程标签:

git tag | grep <pattern> | xargs -n 1 -I% git push origin :refs/tags/%

Delete all your local tags:

删除所有本地标签:

git tag | xargs -n 1 -I% git tag -d %

Fetch the remote tags which still remain:

获取仍然保留的远程标签:

git fetch

回答by Igor Rjabinin

if you have too many tags (like in our case) you might want to do it like:

如果你有太多的标签(比如我们的例子),你可能想要这样做:

git tag -l > tags_to_remove.txt

then edit the file in your preferred editor - to review and remove the tags you want to keep (if any) and then run it locally

然后在您的首选编辑器中编辑文件 - 查看并删除您想要保留的标签(如果有),然后在本地运行它

git tag -d $(cat ./tags_to_remove.txt)

and remotely:

和远程:

git push -d origin $(cat ./tags_to_remove.txt)

回答by Francesco

You can delete multiple tags with one command by specifying all the tags you want to delete

您可以通过指定要删除的所有标签,用一个命令删除多个标签

git tag -d 1.1 1.2 1.3

Then you can push all the deleted tags. Of course you can delete the tags with separate commands before pushing.

然后你可以推送所有删除的标签。当然,您可以在推送之前使用单独的命令删除标签。

To push delete tags, just list all the tags you want to delete. The command is the same to delete one tag

要推送删除标签,只需列出您要删除的所有标签。删除一个标签的命令相同

git push --delete origin 1.1 1.2 1.3