Home > Back-end >  JGit - Checkout to specific remote commit ID hash
JGit - Checkout to specific remote commit ID hash

Time:11-14

I'm trying to access specific commitId files using the JGit library.

Using Git command this would look like : git checkout [COMMIT_ID], then my folder would checkout to the specific commit and get any file from it.

Now using JGit, I'm calling the Git.cloneRepository() function to get my repository (can't clone from a specific commitId here I think sadly). Then I'm trying to checkout using this : gitRepo.checkout().setName(gitCommitId).call()

But this is getting me the folliwing error : Remote origin did not advertise Ref for branch COMMIT_ID. This Ref may not exist in the remote or may be hidden by permission settings.

Which is odd because the CLI git command does work.

Maybe it is not something feasible through this lib but I didn't find anything else on the web yet.

CodePudding user response:

setName(String name) is more for branch name, not for commit ID.

setStartPoint(RevCommit startCommit) does use a commit ID.

As seen here, git.checkout().setAllPaths(true).setStartPoint(gitCommitId).call(); would work better after your clone.

  • Related