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

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

问题描述



我的目标是将它作为一个独特的,增加内部版本号。



我现在在Unix / Cygwin / msysGit上也是这样:

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

但是我觉得这有些破解。



有没有更好的方法来做到这一点?如果我实际上不需要 wc 甚至Git,它会很酷,所以它可以在一个光秃秃的Windows上运行。只读一个文件或一个目录结构......

解决方案

> HEAD , master ,提交哈希):

  git rev-list --count< revision> 

要获得所有分支机构的提交计数:

  git rev-list --all --count 

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


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.

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.

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

解决方案

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天全站免登陆