Number of commits on branch in git
Assuming you branched from master, master..yourbranch
gives you the range of commits that are in yourbranch
but not in master.
Then you just have to list them one line each, and count the number of lines:
git log master..yourbranch --pretty=oneline | wc -l
Update: git rev-list now has --count
:
git rev-list --count master..
With older git versions:
git rev-list master.. |wc -l
rev-list lists revisions, and master..
refers to commits since current HEAD
diverged from master
.
Git can provide you with the number of commits without further shell scripting.
git rev-list master.. --count
rev-list (listed in git help -a
) is used to work with revisions.
As master..
will list the commits from the base of master and the current branch up to the current branch, --count
will give you the count of them.
If you would instead want to have the number of commits between the two revisions you would use master...
. To elaborate: between as in from master to the most recent common ancestor of master and the current branch (HEAD), and up to the current branch again. If you visualize the commit history as a tree you should be able to follow the two branches from the common ancestor. master..
on the other hand will just count one of the two branches.
So whether you want to use master..
or master...
depends on whether you want to know how many commits you made in your branch since you split it off (master..
), or the difference between the current master and branch, the number of commits in master and the branch since the branch was split off.
If you want to see how many commits you or anyone else has made, starting from your current HEAD
, you can do:
git shortlog -sn
Example output:
490 Donald Duck
312 Some Developer
274 John Doe
144 Jane Doe
5 Leet Hacker