Skip to content

Instantly share code, notes, and snippets.

@marcofiset
Forked from lfbittencourt/clear_tags.rb
Last active August 29, 2015 14:04
Show Gist options
  • Save marcofiset/f3a3b1d37dd41f408e0f to your computer and use it in GitHub Desktop.
Save marcofiset/f3a3b1d37dd41f408e0f to your computer and use it in GitHub Desktop.
Delete tags less than a specific version from a git repository, both locally and remotely.
# Tags with version number less than max_tag will be deleted
max_tag = ARGV[0]
if !Gem::Version.correct?(max_tag)
puts 'Incorect version number'
exit
end
tags = `git tag`.split(/\s+/).select do |t|
!Gem::Version::correct?(t) || Gem::Version.new(t) < Gem::Version.new(max_tag)
end
`git tag -d #{tags.join ' '}`
`git push origin #{tags.map { |t| ':' + t }.join ' '}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment