如何删除不在本地存储库中的远程标签

如何删除不在本地存储库中的远程标签

本文介绍了如何删除不在本地存储库中的远程标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让原产地与我的本地标签相匹配.这不要与修剪本地标签混淆,而是要修剪远程标签.

I would like to have origin match my local tags. This is not to be confuse with pruning local tags, but remote instead.

要修剪 local 标签并使我的本地存储库与来源匹配,我会这样做:

To prune local tags and make my local repository match origin I do:

git tag -l | xargs git tag -d
git fetch

我在本地清理了标签,我想推送和删除远程没有的内容.

I cleaned the tags locally and I would like to push and remove what is not up in remote.

我一直在手动操作,例如:

I have been doing it manually like:

git tag -l | grep -v "[^v2]" | xargs git tag -d  # remove local tags that don't match a pattern
git push origin :refs/tags/2.2.15      # manually remove those tags on remote
git push origin :refs/tags/2.2.16
git push origin :refs/tags/2.2.17
git push origin :refs/tags/2.2.18
...

但是有这么多标签,我觉得这可以做不同的事情.那么问题是,如何从远程存储库中删除那些您本地没有的标签?

But with so many tag I feel like this could be done differently.Question is then, How to remove from a remote repository those tags that you do not have locally?

推荐答案

刚刚在远程仓库上测试过,效果很好.

Just tested it on a remote repo and it works fine.

我使用 cut 而不是 grep,并将远程标签与本地标签进行比较,然后删除不同的远程标签.

I used cut instead of grep, and compared the remote tags against the local ones, then removed the remote ones that differed.

git ls-remote --tags origin | cut -f 2 | xargs basename | comm -23 - <(git tag) | awk '{print ":refs/tags/" $0}'  | xargs git push origin

不是世界上最优雅的东西,但它确实有效.

Not the most elegant thing in the world, but it works.

这篇关于如何删除不在本地存储库中的远程标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:38