简体   繁体   中英

How to get the list of commits without cloning the repository in local

My Existing Code

//clone repo
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
private Repository repo;
Git git = Git.cloneRepository()
                    .setCredentialsProvider(credentials)
                    .setURI(url)
                    .setBranch(branch)
                    .setDirectory(localPath)
                    .call();

                repo = git.getRepository();

//get commit by using cloned repo
 try (Git git = new Git(repo)) {
   Iterable<RevCommit> logs = git.log().call();
   for (RevCommit rev : logs) {
    System.out.println("Commit: " + rev + ", name: " + rev.getName() + ", id: " + rev.getId().getName());

        }
    } catch (Exception e) {
        System.out.println("Exception: {}"+e);
    }

Im able to get list of commits by cloning the repository, i want to avoid cloning of repository. Please share me some links if there is a way to do this and also suggest me additional library if needed.

Is has been 8 months for this question. In case anyone else is looking for the same answer.I'll show you how to get tag list with out clone it. In JGit you can use the lsRemoteRepository method

Git.lsRemoteRepository().setRemote(gitUrl).setTags(true).call()

Use this method you can get all the tags in remote responsitory

here you can simply use the git command to get the git logs without having a git copy,

git log -- <git http url

for example git log -- git@github.com/twitter/bootstrap.git

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM