Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the Git commit count?

I'd like to get the number of commits of my Git repository, a bit like SVN revision numbers.

The goal is to use it as a unique, incrementing build number.

I currently do like that, on Unix/Cygwin/msysGit:

git log --pretty=format:'' | wc -l 

But I feel it's a bit of a hack.

Is there a better way to do that? It would be cool if I actually didn't need wc or even Git, so it could work on a bare Windows. Just read a file or a directory structure...

like image 985
Splo Avatar asked Mar 24 '09 13:03

Splo


People also ask

How do I get commit details?

If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

How do I count the number of commits in bitbucket?

It's possible to use the Awesome Graphs app which is free and visualizes the number of commits added by each developer. This Bitbucket REST API query returns the list of commits in a repo so that it's possible to count their number. Hope it helps!


1 Answers

To get a commit count for a revision (HEAD, master, a commit hash):

git rev-list --count <revision> 

To get the commit count across all branches:

git rev-list --all --count 

I recommend against using this for build identifier, but if you must, it's probably best to use the count for the branch you're building against. That way the same revision will always have the same number. If you use the count for all branches, activity on other branches could change the number.

like image 111
4 revs Avatar answered Sep 25 '22 21:09

4 revs