composer.json中带有插入符和代字号的版本号 [英] Version numbers with caret and tilde in composer.json

查看:131
本文介绍了composer.json中带有插入符和代字号的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道composer.json中的插入符号和代字号有什么区别。我可以这样说吗:插入号(^)锁定第一个和第二个版本号(1.2.3中的1.2),而代字号(〜)仅锁定第一个版本号(1.2.3中的1)?

I wonder what is the difference between caret and tilde in 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)?

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

推荐答案

来自您链接的文档:


〜1.2等同于> = 1.2< 2.0.0,而〜1.2.3等同于> = 1.2 .3< 1.3.0

~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.3等效于> = 1.2.3< 2.0.0

^1.2.3 is equivalent to >=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.

插入号几乎总是更好的选择,因为它的行为类似,足以直接替换(〜1.2 ^ 1.2 ^ 1.2.0 相同),但在处理非零值时提供了更好的灵活性修补程序版本( ^ 1.2.3 〜1.2.3 不同,因为代字号仅允许更新低于1.3.0时,脱字符号允许2.0.0以下的更新。)

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).

使用波浪号作为版本要求的唯一原因是必须处理零字符。获得兼容更新的版本。代字号在〜0.1 〜1.1 之间没有区别,在两种情况下都将允许更新到下一个主要版本号(分别低于1.0或2.0)。插入符运算符将不允许在此范围内进行较小的更新: ^ 0.1 不允许将其更新为0.2,因为在语义版本控制中,零点之类的版本可能会在进行版本转换时引入不兼容的更改到零点东西+1。

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). 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.x以上版本(从1.0.0开始),并对自己的代码使用语义版本控制。

  • 在开发阶段,您可以使用 alpha beta rc 稳定性以及预期的最终版本(即 1.0.0-alpha1 )将大致说明 1.0.0 将在未来。

  • 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.
  • For the development phase, you can use alpha, beta or rc stability together with the intended final version, i.e. 1.0.0-alpha1 would be a rough outline of what 1.0.0 will be in the future.

这篇关于composer.json中带有插入符和代字号的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆