Created
January 20, 2012 16:10
-
-
Save nathanl/1648061 to your computer and use it in GitHub Desktop.
Clean up tags in a git repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to delete all but a specified list of tags | |
# from a git repo, both locally and remotely | |
# Run like `mode=test ruby git_tag_cleanup` to test; | |
# use 'execute' mode to actually delete the tags | |
mode = ENV['mode'] || 'test' | |
tags_to_keep = %w[v2.0.0 v2.0.1] | |
tags_to_delete = `git tag`.split("\n") - tags_to_keep | |
puts "Keeping: #{tags_to_keep.inspect}" | |
puts "Deleting: #{tags_to_delete.inspect}" | |
puts "" | |
puts mode == 'execute' ? "Executing!" : "NOT executing - test only" | |
tags_to_delete.each do |tag| | |
delete_locally = "git tag -d '#{tag}'" | |
delete_remote = "git push origin :'#{tag}'" | |
puts delete_locally # to verify output | |
system(delete_locally) if mode == 'execute' | |
puts delete_remote | |
system(delete_remote) if mode == 'execute' | |
end | |
puts "\nDone! Tags remaining are:" | |
puts `git tag` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment