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.
Back to ReferenceVersion Number Structure 5
MAJOR.MINOR.PATCH主版本.次版本.修订号
1.2.3example:主版本 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+20260721Build元数据(+ 号,不影响优先级)
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.0or运算,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