How do you get the author date and commit date from a JGit RevCommit?

git, jgit

Solution

Like so:

RevCommit commit = ...;

PersonIdent authorIdent = commit.getAuthorIdent();
Date authorDate = authorIdent.getWhen();
TimeZone authorTimeZone = authorIdent.getTimeZone();

PersonIdent committerIdent = commit.getCommitterIdent();
...

Also see API documentation.

Problem

`RevCommit` has a `getCommitTime()` method but it returns an `int` and it does not have an author time. How can I get the author and commit date from a `RevCommit`?

Original source