2

With the git command-line, the way to get the git commit count is

git rev-list HEAD --count

How to do this with JGit?

Rüdiger Herrmann
  • 19,689
  • 11
  • 57
  • 75
paleozogt
  • 6,223
  • 11
  • 48
  • 90

2 Answers2

3

You can use the LogCommand to obtain the number of commits like so:

Iterable<RevCommit> commits = git.log().call();
int count = 0;
for( RevCommit commit : commits ) {
  count++;
}

If not specified otherwise the command starts at HEAD. With add() multiple commit-ids can be added to start the graph traversal from or all() can be called to start from all known branches.

Rüdiger Herrmann
  • 19,689
  • 11
  • 57
  • 75
1

More compact answer:

int countCommits = Iterables.size(git.log().call());
Jason Aller
  • 3,475
  • 28
  • 40
  • 37
Gordon Lai
  • 21
  • 3