3

What is the JGit equivalent API for the following command

git log --pretty=format:"%h - %an, %ar : %s"

I want to get the short form of SHA-1 commit id and the status of the file for that particular commit.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79

1 Answers1

4

JGit's LogCommand returns a list of RevCommits from which the information can be obtained.

  • commit id: commit.getId()
  • author name: commit.getAuthor().getName()`
  • author date: commit.getAuthor().getWhen()`
  • subject: commit.getShortMessage()`

To shorten a Git object id in JGit, you can use the abbreviate() method. For example:

RevCommit commit = ...
ObjectId commitId = commit.getId();
String shortId = commitId.abbreviate( 7 ).name();

will shorten the given objectId to 7 characters.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79