To count the commits for the branch you are on:
git rev-list --count HEAD
for the branch
git rev-list --count <branch-name>
If you want to count commits on a branch created since the branch was created
git rev-list --count HEAD ^<branch-name>
This will reckon with all commits ever made that are also not related to the branch name.
Examples
git checkout master git checkout -b test <We do 3 commits> git rev-list --count HEAD ^master
Result: 3
If your branch comes from a branch called develop :
git checkout develop git checkout -b test <We do 3 commits> git rev-list --count HEAD ^develop
Result: 3
Ignore merge
If you merge another branch into the current branch without fast-forwarding, and you do it higher, merging is also taken into account. This is because for git, merging is a commit.
If you do not want to read these commits, add --no-merges :
git rev-list --no-merges --count HEAD ^develop
Peter van der Does Jul 25 '12 at 19:58 2012-07-25 19:58
source share