0

Given a git tag (ex. v.0.1.0) I would like a bash command that will give me the previous chronological tag (ex. v.0.0.5). Here I'm using semver for version control and you can see that I can't just decrement the numbers. I need the previous last tag that was given to the repo. Thoughts?

I've tried git describe --tags and its giving me the last tag kindof. But nothing this specific.

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • Is there a problem with the `git describe --tags` output? Is it incorrect? Is it information than you need? Something else? – Etan Reisner Jan 26 '15 at 19:48

1 Answers1

1

There are several solutions out there for listing your tags in chronological order. The one that I often use is:

git for-each-ref --sort=authordate --format '%(refname) %(authordate)' refs/tags

This works fine if all your tags are "lightweight" tags. If all your tags are annotated tags, use taggerdate instead of authordate. With your tags listed in chronological order, it should be easy to find the tag chronologically prior to any other given tag.

See also:

Community
  • 1
  • 1
larsks
  • 277,717
  • 41
  • 399
  • 399