简体   繁体   English

如何获取$git描述的单个元素?

[英]How to get individual elements of $ git describe?

We are working on a versioning system based on git tags.我们正在开发基于 git 标签的版本控制系统。 While git describe is great, we would prefer commands that output the three elements of git describe seperately (latest tag, commits since tag, commitId) eg TAG 12 gff9fd30 .虽然git describe很棒,但我们更喜欢命令 output git 的三个元素分别描述(最新标记、自标记以来的提交、commitId),例如TAG 12 gff9fd30 We managed getting the commitId with git rev-parse HEAD , but don't know if there are any commands for only getting the latest tag and the commits since that tag.我们设法使用git rev-parse HEAD获取了 commitId,但不知道是否有任何命令只获取最新的标签和自该标签以来的提交。

Of course it would be possible to split the output at hyphens, but if there is a cleaner solution, we would prefer it.当然可以在连字符处拆分 output,但如果有更简洁的解决方案,我们会更喜欢它。

Thanks for any hints!感谢您的任何提示!

only getting the latest tag只获取最新的标签

git describe --tags --abbrev=0

commits since that tag自该标记后提交

git log LATEST_TAG..HEAD , you can use --pretty to format the logs. git log LATEST_TAG..HEAD ,您可以使用--pretty来格式化日志。

Latest tag in the current branch:当前分支的最新标签:

git describe --tags --abbrev=0

(Found in https://stackoverflow.com/a/7261049/7976758 , search: https://stackoverflow.com/search?q=%5Bgit%5D+latest+tag ) (发现于https://stackoverflow.com/a/7261049/7976758 ,搜索: https://stackoverflow.com/search?q=%5Bgit%5D+latest+tag

Count commits since a commit:自提交以来计数提交:

git rev-list --count <revision>..

(Please note .. ; https://stackoverflow.com/a/4061706/7976758 , https://stackoverflow.com/search?q=%5Bgit%5D+count+commits ). (请注意..https://stackoverflow.com/a/4061706/7976758,https ://stackoverflow.com/search?q=%5Bgit%5D+count+commits )。

Overall:总体:

git rev-list --count $(git describe --tags --abbrev=0)..

Or或者

lasttag=$(git describe --tags --abbrev=0)
git rev-list --count $lasttag..

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

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