tisdag 30 maj 2017

Delete batches of tags in git

List tags

To list all tags, run
git tag

To list tags matching a pattern, use
git tag -l name_pattern 

For example, to list all tags with a name that begins with Release
git tag -l Release*

Delete tags locally

To delete a single tag
git tag -d name_of_tag

To delete multiple tags
git tag -d name_of_tag1 name_of_tag2

To delete all tags locally
git tag | xargs git tag -d  
(xargs takes the output from the first command and passes it as argument to the next)

To delete all tags that matches a name pattern
git tag -l Release* | xargs git tag -d

Delete tags on the remote

Assuming the remote is named origin and you want to delete all release tags for the 1.x and 2.x releases
git tag -l {Release/1.*,Release/2.*} | xargs git push --delete origin

REMEMBER to make sure that your pattern ONLY matches the tags that you want to delete. Inspect the result from the listing of matched tags before piping them to the next command.

Inga kommentarer:

Skicka en kommentar