统计Git分支上的提交数量 [英] Count the number of commits on a Git branch

查看:669
本文介绍了统计Git分支上的提交数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了这个答案: git中分支提交的次数
,但假设分支是由master创建的。



如何计算分支的提交数量依赖于这个假设?



在SVN中,这是微不足道的,但出于某种原因,真的很难在git中弄清楚。

  

git rev-list --count HEAD

分行

  git rev-list --count< branch-name> 

如果您想要计算自从创建分支以来在分支上进行的提交

  git rev-list --count HEAD ^< branch-name> 

这将计算所有不属于分支名称的提交。



示例



  git checkout master 
git checkout -b test
<我们做3次提交>
git rev-list --count HEAD ^ master

结果:3



如果您的分支来自名为 develop 的分支:

  git checkout开发
git checkout -b测试
<我们做3次提交>
git rev-list --count HEAD ^ develop

结果:3



忽略合并



如果您将另一个分支合并到当前分支而没有快进,并且执行了上述操作,合并也是计数。这是因为对于git来说,merge是一个提交。



如果您不想计算这些提交,请添加 - no-merges < code $:

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


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 <branch-name>

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

git rev-list --count HEAD ^<branch-name>

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

Examples

git checkout master
git checkout -b test
<We do 3 commits>
git rev-list --count HEAD ^master

Result: 3

If your branch comes of a branch called develop:

git checkout develop
git checkout -b test
<We do 3 commits>
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

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

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