How to delete redundant tags in Git warehouse?

Time:2021-3-7

For example, tag:

b_3.0.18_201806201808
b_3.0.18_201806201819
b_3.0.18_201806212108

1. Delete one by one

  • Delete tag locally:
git  tag -d b_3.0.18_201806201808
git  tag -d b_3.0.18_201806201819
git  tag -d b_3.0.18_201806212108
  • Delete remote Tag:
git push origin :refs/tags/b_3.0.18_201806201808
git push origin :refs/tags/b_3.0.18_201806201819
git push origin :refs/tags/b_3.0.18_201806212108
  • View local Tags:git tag -l
  • View remote Tags:git show-ref --tag

so much trouble!!!

2. Batch deletion

Using awk regular expressions

reference resources:

http://javascript.ruanyifeng….

https://www.cnblogs.com/OldJa…

This example can be:/^b_4.0.0_201806[0-9]{6}$/

  • Batch delete local:
git tag -l| awk '/^b_4.0.0_201806[0-9]{6}$/ {print  $1}' | xargs git tag -d
  • Batch delete remote:
git show-ref --tag | awk '/^b_4.0.0_201806[0-9]{6}$/ {print ":" $2}' | xargs git push origin
  • View local:git tag -l
  • View remote: git show-ref --tag