paleozogt
paleozogt

Reputation: 6573

Use JGit to get the git commit count

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?

Upvotes: 4

Views: 1484

Answers (2)

Gordon Lai
Gordon Lai

Reputation: 41

More compact answer:

int countCommits = Iterables.size(git.log().call());

Upvotes: 2

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 21025

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.

Upvotes: 4

Related Questions