SemVer Cheatsheet - Semantic Versioning Reference

All essential SemVer commands organized by use case, with 33+ entries you can copy and run directly. Find the right command fast when you need it.

Reference·33 commands·Last updated 2026-07-21
Back to Reference

Version Number Structure 5

MAJOR.MINOR.PATCH
主版本.次版本.修订号
1.2.3
example:主版本 1,次版本 2,修订号 3
MAJOR:不兼容的 API 变更
破坏性Update时递增
MINOR:向下兼容的功能新增
新增功能时递增
PATCH:向下兼容的问题修复
修复 bug 时递增

Pre-release & Build Metadata 6

1.0.0-alpha.1
内部Test版(alpha)
1.0.0-beta.2
公开Test版(beta)
1.0.0-rc.1
候选release版(release candidate)
alpha < beta < rc < 正式版
先行版本号优先级order
1.0.0-alpha < 1.0.0-alpha.1
同标识按数字递增compare
1.0.0+20260721
Build元数据(+ 号,不影响优先级)

Version Comparison Operators 5

=1.2.3
精确Match指定版本
>1.2.3
大于指定版本(不含)
>=1.2.3
大于于指定版本
<2.0.0
小于指定版本(不含)
<=1.9.9
小于于指定版本

npm Version Range Symbols 7

^1.2.3
允许 1.x.x,不允许 2.0.0(兼容版本)
~1.2.3
允许 1.2.x,不允许 1.3.0(接近版本)
1.2.3 - 2.3.4
区间范围(>=1.2.3 且 <=2.3.4)
1.x
通配符,equivalent to >=1.0.0 <2.0.0
1.2.x
通配符,equivalent to >=1.2.0 <1.3.0
*
任意版本(不recommended,易引入破坏性Upgrade)
latest
最新稳定版(dist-tag)

npm Advanced Range Syntax 5

1.2.3 || >=2.0.0
or运算,Match任一范围
>=1.2.3 <2.0.0
空格表示 AND,需同时满足
~1.2 || ^2.0.0
复合范围组合使用
github:owner/repo
从 Git 仓库Install
file:./local-pkg
从本地路径Install

Version Changes & Release Rules 5

feat: 新功能
对应 MINOR 递增
fix: 修复 bug
对应 PATCH 递增
BREAKING CHANGE: 破坏性变更
对应 MAJOR 递增
0.x.x
主版本号为 0 表示初始开发,API 不稳定
1.0.0
首个正式版,标志着公共 API 稳定

Tips

  • ^1.2.3 等价于 >=1.2.3 <2.0.0,是 npm install 的默认行为。
  • ~1.2.3 等价于 >=1.2.3 <1.3.0,只允许补丁版本更新。
  • package-lock.json 锁定精确版本,避免 ^ 和 ~ 带来的不确定性。
  • 破坏性变更必须递增主版本号,即使只是小改动。
  • 主版本号为 0(0.x.x)时,任何向下不兼容的变更都应递增次版本号。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us