Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


There’s even a GNU C Library function: strverscmp():

https://www.gnu.org/software/libc/manual/html_node/String_00...


git directly uses that function :)

(... well, it's copied and pasted into the tree but close enough)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: