首页 > 解决方案 > 使用 JGit 库提交后如何获取提交的 id

问题描述

我正在使用下面的代码来提交我的更改。

CommitCommand commitCommand = git.commit();
commitCommand.setMessage("My change");
commitCommand.setAuthor(name, name + "@xyz.com");
commitCommand.call();

我想知道此更改的提交 ID。因为可以有 || 在我获得最新的提交 ID 和这个特定的提交之间的过程提交。因此,要在此特定提交中发生更改,我需要上述提交的提交 ID。AFAIK CommitCommand 没有 getID() API。

标签: javajgit

解决方案


一种选择是使用RevCommit,如下所示:

        //Run commit cmd with commit msg
    RevCommit revCommit = git.commit()
            .setMessage(commitMsg)
            .call();
    log.info("Commint ID " + revCommit.getId().getName());

推荐阅读