how do I get all commits of a branch with JGit, without changing the working directory?
Unfortunately the JGit docs are not very good ...
In ruby with grit i
I was just looking for a way to list all commits under each branch and I found this thread. I finally did something a bit different from some of the answers I found here and worked.
public static void main(String[] args) throws IOException, GitAPIException {
Repository repo = new FileRepository("pathToRepo/.git");
Git git = new Git(repo);
List branches = git.branchList().call();
for (Ref branch : branches) {
String branchName = branch.getName();
System.out.println("Commits of branch: " + branchName);
System.out.println("-------------------------------------");
Iterable commits = git.log().add(repo.resolve(branchName)).call();
List commitsList = Lists.newArrayList(commits.iterator());
for (RevCommit commit : commitsList) {
System.out.println(commit.getName());
System.out.println(commit.getAuthorIdent().getName());
System.out.println(new Date(commit.getCommitTime() * 1000L));
System.out.println(commit.getFullMessage());
}
}
git.close();
}
Thanks for the help