Skip to content

Instantly share code, notes, and snippets.

@triplepoint
Last active February 26, 2016 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triplepoint/bb29d7377beb5e0f0055 to your computer and use it in GitHub Desktop.
Save triplepoint/bb29d7377beb5e0f0055 to your computer and use it in GitHub Desktop.
How to remove tags of the form 'X.Y.Z',
#! /usr/bin/env bash
set -e
# The prefix 'namespace' in tags of the form 'some_prefix/x.y.z'
PROJECT_PREFIX="some_prefix"
# Get all the current tags on the repository
TAGS=`git tag`
### ADD PREFIXES TO ALL THE 'X.Y.Z' TAGS
for TAG in $TAGS; do
echo "Tag: $TAG"
# If the tag doesn't fit the x.y.z form, skip it
if ! [[ $TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then
echo "!!! tag doesn't match X.Y.Z pattern, skipping";
continue;
fi
# Define what the new tag would look like
NEW_TAG=$PROJECT_PREFIX/$TAG
echo "--- new tag $NEW_TAG"
# If the new tag already exists, skip it
if `git rev-list $NEW_TAG.. >/dev/null 2>&1`; then
echo "!!! new tag exists already, skipping"
continue;
fi
# Add the new tag
COMMIT=`git rev-parse $TAG`
echo "*** ADDING NEW TAG $NEW_TAG for commit $COMMIT"
git tag -a $NEW_TAG -m "Tagging $NEW_TAG" $COMMIT
done
#! /usr/bin/env bash
set -e
# Remove all git tags from the working copy, and fetch all tags from the remote
git tag -l | xargs git tag -d && git fetch -t
#! /usr/bin/env bash
set -e
# The prefix 'namespace' in tags of the form 'some_prefix/x.y.z'
PROJECT_PREFIX="some_prefix"
# Get all the current tags on the repository
TAGS=`git tag`
### REMOVE TAGS WITH THE ABOVE PREFIX
for TAG in $TAGS; do
echo "Tag: $TAG"
# If the tag doesn't match the form `prefix/x.y.z`, skip it, we're not deleting it
if ! [[ $TAG =~ ^$PROJECT_PREFIX/[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then
echo "--- No Match, skipping"
continue;
fi
echo "!!! Match, removing"
git tag --delete $TAG
# Also remove the tag from the origin remote
git push origin :refs/tags/$TAG
done
#! /usr/bin/env bash
set -e
# Get all the current tags on the repository
TAGS=`git tag`
### REMOVE TAGS WITH NO PREFIX
for TAG in $TAGS; do
echo "Tag: $TAG"
# If the tag doesn't match the form `x.y.z`, skip it, we're not deleting it
if ! [[ $TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ; then
echo "--- No Match, skipping"
continue;
fi
echo "!!! Match, removing"
git tag --delete $TAG
# Also remove the tag from the origin remote
git push origin :refs/tags/$TAG
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment