git 统计分支个数,统计Git分支上的提交数量

I found this answer already: Number of commits on branch in git

but that assumes that the branch was created from master.

How can I count the number of commits along a branch without relying on that assumption?

In SVN this is trivial, but for some reason is really difficult to figure out in git.

解决方案

To count the commits for the branch you are on:

git rev-list --count HEAD

for a branch

git rev-list --count

If you want to count the commits on a branch that are made since you created the branch

git rev-list --count HEAD ^

This will count all commits ever made that are not on the branch-name as well.

Examples

git checkout master

git checkout -b test

git rev-list --count HEAD ^master

Result: 3

If your branch comes of a branch called develop:

git checkout develop

git checkout -b test

git rev-list --count HEAD ^develop

Result: 3

Ignoring Merges

If you merge another branch into the current branch without fast forward and you do the above, the merge is also counted. This is because for git a merge is a commit.

If you don't want to count these commits add --no-merges:

git rev-list --no-merges --count HEAD ^develop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值