Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown
read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown [message #1793175] Wed, 01 August 2018 00:17 Go to next message
Nguyen Tien is currently offline Nguyen TienFriend
Messages: 1
Registered: July 2018
Junior Member

I write a snipet to read git commit from some git repo. But it failed to read some repo. Here are the error

grafana-master/grafana-plugins/.git indexed repo failed
org.eclipse.jgit.errors.MissingObjectException: Missing unknown 7202bc6573821ed3ba371c895fff0b00102674d2
at org.eclipse.jgit.revwalk.RevWalk.parseAny(
at org.eclipse.jgit.revwalk.RevWalk.parseCommit(

- the repo is, it is clone locally
- the repo is clean, no local change or commit
- my jgit version is latest
- my code is as follow

Repository repository = repositoryBuilder.setGitDir(gitFolder)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
Git git = new Git(repository);
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(lastCommitId);

It failed in the last line 'RevCommit commit = walk.parseCommit(lastCommitId);'

I also try to read git repo with git.log().all().call();
but it still failed with the same error.

That code work well with other repos, but failed to read some repo.

Please advice me how to solve this issue.

Re: read commit failed with org.eclipse.jgit.errors.MissingObjectException: Missing unknown [message #1793850 is a reply to message #1793175] Fri, 17 August 2018 08:54 Go to previous message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 267
Registered: July 2009
Senior Member
For me this code works when called with "" and "HEAD"

public class CloneRepoIntoTmpAndInspectHEAD {
	public static void main(String args[]) throws IOException, GitAPIException, JGitInternalException {
		Path tmp = Files.createTempDirectory("JGitTest_" + CloneRepoIntoTmpAndInspectHEAD.class.getName());
		try (Git git = Git.cloneRepository().setDirectory(tmp.toFile()).setURI(args[0]).setBare(false).call()) {
			System.out.println("Repo " + args[0] + " cloned to " + tmp);
			Repository repo = git.getRepository();
			ObjectId lastCommitId = repo.resolve(Constants.HEAD);
			try (RevWalk walk = new RevWalk(repo)) {
				RevCommit commit = walk.parseCommit(lastCommitId);
				System.out.println("Commit " + lastCommitId + " has message " + commit.getShortMessage());
		} finally {
			Files.walk(tmp).map(Path::toFile).sorted((o1, o2) -> -o1.compareTo(o2)).forEach(File::delete);

Previous Topic:Help:A cycle was detected when generating the classpath
Next Topic:Java 11 Compatibility check: JGit
Goto Forum:

Current Time: Thu Feb 20 13:57:05 GMT 2020

Powered by FUDForum. Page generated in 0.01870 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top