How to obtain the RevCommit or ObjectId from a SHA1 ID string with JGit?

It is probably easier to first convert the string into an ObjectId and then have the RevWalk look it up.

ObjectId commitId = ObjectId.fromString("ab434...");
try (RevWalk revWalk = new RevWalk(repository)) {
  RevCommit commit = revWalk.parseCommit(commitId);
}

Notice that RevWalk is now auto-closable, so you can also use the try-with-resources statement:

try (RevWalk revWalk = new RevWalk(repository)) {
    RevCommit commit = revWalk.parseCommit(commitId);
}

Tags:

Sha1

Jgit