Skip to content
shellhacks.dev
Git

Semver Version Sorter

Sort a list of version numbers by Semantic Versioning precedence (1.10.0 after 1.9.12, betas before releases), dedupe them, and see the next major, minor, patch and pre-release.

Free · No sign-up · Your inputs stay in your browser

Input

Sort version numbers by semver

Output

Latest: 2.0.0

Sorted

2.0.0 2.0.0-alpha v1.10.0 v1.9.12 v1.2.0 1.2.0-rc.1 1.2.0-beta.11 1.2.0-beta.2

Not semver: release-candidate

Next major3.0.0
Next minor2.1.0
Next patch2.0.1
Next prerelease2.0.1-rc.0

Semantic Versioning 2.0.0 order: numbers compare numerically (1.10.0 is newer than 1.9.12, which a plain text sort gets wrong), a pre-release sorts before its release, and pre-release identifiers compare numerically when they are numbers, so beta.11 comes after beta.2. Build metadata after + is ignored. sort -V in GNU coreutils gets most of this right too.

Runs in this browser. Nothing you paste is sent to a server.

Why text sorting fails

Sorted as text, 1.10.0 comes before 1.9.0 and beta.11 before beta.2. SemVer compares numeric parts as numbers, puts a pre-release before its release, compares pre-release identifiers numerically when they are numbers, and ignores build metadata, as the specification's precedence rules define.

Tags in Git

git tag --sort=-v:refname sorts tags by version, and GNU sort -V gets most cases right, though both treat pre-releases differently from SemVer in some edge cases.

Share

Frequently asked questions

Is 1.0.0-rc.1 before or after 1.0.0?
Before. A pre-release has lower precedence than the release with the same version numbers.
Does a leading v matter?
Not to SemVer precedence. v1.2.3 is the Git tag convention for version 1.2.3.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Keep planning

Similar tools