SHA-1 提交 ID 的缩写形式

Short form of SHA-1 commit id

以下命令的 JGit 等价物是什么API

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

我想获取 SHA-1 提交 ID 的缩写形式以及该特定提交的文件状态。

JGit's LogCommand returns 可以从中获取信息的 RevCommit 列表。

  • 提交 ID:commit.getId()
  • 作者姓名:commit.getAuthor().getName()`
  • 作者日期:commit.getAuthor().getWhen()`
  • 主题:commit.getShortMessage()`

要缩短 JGit 中的 Git 对象 ID,可以使用 abbreviate() 方法。 例如:

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

会将给定的 objectId 缩短为 7 个字符。