5 ms·
In fact there are standard-ish sorting methods that work fine with mixed text and version numbers such that 1.100 is more than 1.2, and v1.100 is more than v1.2
by jlokier 4y ago
In fact there are standard-ish sorting methods that work fine with mixed text and version numbers such that 1.100 is more than 1.2, and v1.100 is more than v1.2.
Git has built in version sort, though it's not the default. GitHub shows tags in version sort order in the drop-down tag selection.
Here are some commands that use that sort order:
ls -v # Linux only.
ls | sort -V # Most modern OSes.
git tag | sort -V # Git tags in version order.
git tag --sort=v:refname # Same as above, it's a git builtin.
git config tag.sort v:refname # Set default sort order for `git tag`.
git config versionsort.suffix -pre # Make 1.2-pre1 sort before 1.2.
git config versionsort.suffix -rc # Now 1.2-pre1 < 1.2-rc1 < 1.2 < 1.2-patch1
- teddyh 4y agoThere’s even a GNU C Library function: strverscmp(): https://www.gnu.org/software/libc/manual/html_node/String_002fArray-Comparison.html#index-strverscmp https://www.gnu.org/software/libc/manual/html_node/String_00...
- blibble 4y agogit directly uses that function :) (... well, it's copied and pasted into the tree but close enough)