Igdrasil35
Igdrasil35

Reputation: 17

How to get the log in reverse order with JGit?

I'm looking for the equivalent command in JGit for

git log --reverse

Can it be done by editing the config file for git.log().all().call()?

Upvotes: 2

Views: 728

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 20985

JGit's LogCommand does not allow to specify the order in which commits are listed.

The underlying RevWalk, however, can be used directly and allows to change the sort order, for example:

RevWalk walk = new RevWalk( repository );
walk.sort( RevSort.COMMIT_TIME_DESC, true );
walk.sort( RevSort.REVERSE , true );
RevCommit commit = walk.next();
while( commit != null ) {
  // use commit
  commit = walk.next();
}
walk.close();

Upvotes: 3

Related Questions