简体   繁体   English

在composer.json中带有插入符号和波浪号的版本号

[英]Version numbers with caret and tilde in composer.json

I wonder what is the difference between caret and tilde in composer.json. 我想知道composer.json中插入符号和波形符号之间的区别是什么。 Can I say it like this: caret (^) lock the first and the second version number (the 1.2 in 1.2.3) and tilde(~) lock only the first version number (the 1 in 1.2.3)? 我可以这样说:插入符号(^)锁定第一个和第二个版本号(1.2.3中的1.2)和波浪号(〜)只锁定第一个版本号(1.2.3中的1)?

https://getcomposer.org/doc/articles/versions.md#next-significant-release-operators https://getcomposer.org/doc/articles/versions.md#next-significant-release-operators

From the documentation you linked: 从您链接的文档:

~1.2 is equivalent to >=1.2 <2.0.0, while ~1.2.3 is equivalent to >=1.2.3 <1.3.0 ~1.2相当于> = 1.2 <2.0.0,而~1.2.3相当于> = 1.2.3 <1.3.0

^1.2.3 is equivalent to >=1.2.3 <2.0.0 ^ 1.2.3相当于> = 1.2.3 <2.0.0

The tilde depends on how many digits in the version number are given. 代字号取决于版本号中的位数。 The last digit given can vary. 给出的最后一位数可以变化。

The caret is almost always the better choice because it acts similarly enough to be a direct replacement ( ~1.2 is the same as ^1.2 or ^1.2.0 ), but offer better flexibility when addressing non-zero patch versions ( ^1.2.3 is NOT the same as ~1.2.3 , because the tilde version only allows updates below 1.3.0, the caret allows updates below 2.0.0). 插入符号几乎总是更好的选择,因为它的行为类似于直接替换( ~1.2^1.2^1.2.0 ),但在处理非零补丁版本时提供更好的灵活性( ^1.2.3~1.2.3 ,因为波浪号版本只允许1.3.0以下的更新,插入符允许更新低于2.0.0)。

The only reason why one would use the tilde as version requirement is if you have to deal with "zero" versions that get compatible updates. 使用代字号作为版本要求的唯一原因是,如果您必须处理获得兼容更新的“零”版本。 The tilde does not differ between ~0.1 and ~1.1 , in both cases it will allow updates up to the next major version number (below 1.0 or 2.0 respectively). 波浪号在~0.1~1.1之间没有差别,在这两种情况下,它都允许更新到下一个主要版本号(分别低于1.0或2.0)。 The caret operator will disallow minor updates in this range: ^0.1 does not allow updates to 0.2, because in semantic versioning a zero-dot-something version may introduce incompatible changes when going to zero-dot-something+1. 插入符号操作符将禁止此范围内的次要更新: ^0.1不允许更新为0.2,因为在语义版本控制中,零点式版本可能会在转到零点点+ 1时引入不兼容的更改。

Summary: 摘要:

  • Prefer the caret operator - it's the easiest way to force minimum patch versions. 喜欢插入符号操作符 - 这是强制最小补丁版本的最简单方法。
  • Prefer versions above 0.x (start with 1.0.0) and use semantic versioning for your own code. 首选版本高于0.x(从1.0.0开始)并为您自己的代码使用语义版本控制。
  • For the development phase, you can use alpha , beta or rc stability together with the intended final version, ie 1.0.0-alpha1 would be a rough outline of what 1.0.0 will be in the future. 对于开发阶段,您可以将alphabetarc稳定性与预期的最终版本一起使用,即1.0.0-alpha1将是1.0.0将来的概要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM