我只想從Git倉庫中檢索提交日誌,其中包含針對特定reprobitory所做的所有提交的消息。我發現了一些代碼片段來實現這一點,並以異常結束。從Git中檢索提交消息日誌使用JGit
try {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = builder.setGitDir(new File("https://github.com/name/repository.git")).readEnvironment().findGitDir().build();
RevWalk walk =new RevWalk(repo);
ObjectId head = repo.resolve(Constants.HEAD);
RevCommit commit =walk.parseCommit(head);
Git git =new Git(repo);
Iterable<RevCommit> gitLog = git.log().call();
Iterator<RevCommit> it = gitLog.iterator();
while(it.hasNext())
{
RevCommit logMessage = it.next();
System.out.println(logMessage.getFullMessage());
}
}
catch(Exception e) {
e.printStackTrace();
}
但是它給了我:
org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified exception.
如何擺脫呢?我使用org.eclipse.jgit JAR版本2.0.0.201206130900-R
赫爾曼。這看起來不錯,但我需要的是什麼,我已經本地源這是我加入到混帳回購協議的一個。但是現在我想顯示我的提交消息,並且不想再次克隆我已有的目錄。怎麼做? –
您可以打開一個現有的本地存儲庫,如下所示:'Repository repo = builder.setGitDir(new File(「/ path/to/local/repo/.git」))。setMustExist(true).build();' –
..偉大的作品...我也列出了我的提交日誌。 –