我如何获得 Git 提交计数? [英] How do I get the Git commit count?

查看:18
本文介绍了我如何获得 Git 提交计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取我的 Git 存储库的提交次数,有点像 SVN 修订号.

I'd like to get the number of commits of my Git repository, a bit like SVN revision numbers.

目标是将其用作唯一的、递增的内部版本号.

The goal is to use it as a unique, incrementing build number.

我目前喜欢这样,在 Unix/Cygwin/msysGit 上:

I currently do like that, on Unix/Cygwin/msysGit:

git log --pretty=format:'' | wc -l

但我觉得这有点像黑客.

But I feel it's a bit of a hack.

有没有更好的方法来做到这一点?如果我真的不需要 wc 甚至 Git,那就太酷了,这样它就可以在裸机上运行.只需读取文件或目录结构...

Is there a better way to do that? It would be cool if I actually didn't need wc or even Git, so it could work on a bare Windows. Just read a file or a directory structure...

推荐答案

获取修订的提交计数(HEADmaster、提交哈希):

To get a commit count for a revision (HEAD, master, a commit hash):

git rev-list --count <revision>

获取所有分支的提交计数:

To get the commit count across all branches:

git rev-list --all --count

我建议不要将它用于构建标识符,但如果必须,最好使用您正在构建的分支的计数.这样,相同的修订版将始终具有相同的编号.如果您对所有分支使用计数,则其他分支的活动可能会更改数量.

I recommend against using this for build identifier, but if you must, it's probably best to use the count for the branch you're building against. That way the same revision will always have the same number. If you use the count for all branches, activity on other branches could change the number.

这篇关于我如何获得 Git 提交计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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