Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of commits on branch in git

I'm writing a small script and want to know how many commits I made on a current branch since it was created.

In this example I'd have 2 commits made on child:

git checkout master git checkout -b child ... git commit -a ... git commit -a 

So what I want is

commit_number = ... echo $commit_number 
like image 445
Andrey Ermakov Avatar asked Jun 06 '12 12:06

Andrey Ermakov


People also ask

How do you count the number of commits?

To get the number of commits for each user execute git shortlog -sn --all. To get the number of lines added and delete by a specific user install q and then execute: git log --author="authorsname" --format=tformat: --numstat | q -t "select sum(c1), sum(c2) from -"

How do you see all commits on a branch?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

How many commits can git handle?

1 accepted. Hi @Diliup-G , We don't have a limit on the number of commits per repository.


1 Answers

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.

like image 142
Kissaki Avatar answered Sep 22 '22 01:09

Kissaki