且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Git中管理版本号?

更新时间:2023-01-15 09:59:12

亚历山大·基瑟列夫(Alexey Kiselev)和达里奥(Dario)已经暗示要回答这个问题,但我将尝试对其进行详细解释.

Alexey Kiselev and Dario already hinted towards the answer, but I will try to explain it in detail.

有两种类型的版本控制方案:

There are two types of versioning schemes:

  1. 内部版本号:一天之内可以增加多次(例如版本控制号)
  2. 已发布的版本:更改频率较低(例如语义版本控制)

人们根据需要使用不同的方案,但是

People use different schemes as per their need, but semantic versioning is fairly widely used and authored by Tom Preston-Werner, co-founder of GitHub.

语义版本控制遵循X.Y.Z

或更易读的将是[major].[minor].[patch]-[build/beta/rc]

例如1.2.0-beta

major or X可以递增.

minor or Y会递增.

patch or Z会增加.

通过使用标签:

Git中的标签可用于添加版本号.

Tags in Git can be used to add a version number.

git tag -a "v1.5.0-beta" -m "version v1.5.0-beta"

将v1.5.0-beta的版本标签添加到您当前的Git存储库中.此后的每个新提交都将通过追加提交编号和提交哈希值来自动递增标记.可以使用git describe命令查看.

adds a version tag of v1.5.0-beta to your current Git repository. Every new commit after this will auto-increment tag by appending commit number and commit hash. This can be viewed using the git describe command.

v1.5.0-beta-1-g0c4f33f,其中-1-是提交编号,而0c4f33f是提交哈希的缩写. g前缀代表"git".

v1.5.0-beta-1-g0c4f33f here -1- is the commit number and 0c4f33f the abbreviation of commit's hash. The g prefix stands for "git".

可以使用以下方法查看完整的详细信息:

Complete details can be viewed using:

git show v1.5.0-beta