我想获得Git存储库的提交数量,有点像SVN的修订号。

我们的目标是将其用作唯一的、递增的构建号。

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

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

但我觉得它有点过时了。

有更好的办法吗?如果我实际上不需要wc甚至Git,那么它就可以在裸Windows上工作,那就太棒了。只要读取一个文件或目录结构…


当前回答

有一些很酷的方法可以做到这一点

第一个方法

git shortlog -s

该命令打印所有参与repo的用户的提交计数列表。

956 Pankaj Tanwar
235 The Ninja
540 The Hardcore Geek
664 The Ever Shining Star
984 The Experienced Man

简单地说,要获得总提交数-

git shortlog -s |抓住“潘卡伊·坦瓦尔”

它打印-

956 Pankaj Tanwar

另一种干净又酷的方法是-

git rev-list HEAD --author="Pankaj Tanwar" --count 

要计算贡献的代码行数和提出的拉请求总数,请查看此博客

其他回答

有一些很酷的方法可以做到这一点

第一个方法

git shortlog -s

该命令打印所有参与repo的用户的提交计数列表。

956 Pankaj Tanwar
235 The Ninja
540 The Hardcore Geek
664 The Ever Shining Star
984 The Experienced Man

简单地说,要获得总提交数-

git shortlog -s |抓住“潘卡伊·坦瓦尔”

它打印-

956 Pankaj Tanwar

另一种干净又酷的方法是-

git rev-list HEAD --author="Pankaj Tanwar" --count 

要计算贡献的代码行数和提出的拉请求总数,请查看此博客

要获得两个分支(如feature分支和目标使用分支)之间不同的提交数:

Git rev-list——count feature_branch..target_branch

要将其转换为变量,最简单的方法是:

export GIT_REV_COUNT=`git rev-list --all --count`

你可以用:

git shortlog -s -n

结果:

 827  user one
    15  user two
     2  Gest 

做一个别名怎么样?

alias gc="git rev-list --all --count"      #Or whatever name you wish