A lot of people use semantic versioning with their git tags. Like this:
Getting the most recent version (or all of the versions in order) is a pain because sorting them doesn’t give the correct semantic order:
The v0.10.7 mistakenly appears before the v0.3.12 because '1' < '3'.
If your versions do not have the v prefix, you can simply use:
However, if your versions do contain the v prefix (or any other prefix for that matter) you will have to strip it out before the sort, like:
Notice that the prefix is stripped off with tr, but then appended after the sort with xargs.
- You can use head or tail to find the most recent or oldest versions respectively.
- Add -r to the sort command to get the versions in reverse.
- Use grep to filter the tags before performing the sort. This is helpful if you have other tags that are not versions or should not be included in the output.