我正在使用此代码创建包含已更改文件的powerpoint:
try (Git git = new Git(repo)) {
DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
df.setRepository( git.getRepository() );
Iterable<RevCommit> commits = git.log().all().call();
for (RevCommit commit : commits) {
if(commit.getParents().length != 0) {
System.out.println("LogCommit: " + commit);
List<DiffEntry> entries = df.scan(commit.getId(), commit.getParent(0).getId());
for( DiffEntry entry : entries ) {
String filename = entry.getPath(DiffEntry.Side.NEW);
if(!filename.equals("/dev/null")) {
Integer currentCount = 0;
if(fileChanges.containsKey(filename)) {
currentCount = fileChanges.get(filename);
}else {
System.out.println(" DiffEntry: " +entry.getPath(DiffEntry.Side.NEW));
}
fileChanges.put(filename, new Integer(currentCount + 1));
}
}
}
}
}
然而,当我在回购时运行它:
org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified
at org.eclipse.jgit.api.LogCommand.call(LogCommand.java:154)
at .GitAccessor.getFilesChanged(GitAccessor.java:47)
at Main.main(Main.java:45)
我试图复制它(因为它在客户端的机器上)通过在没有主服务器的情况下创建这个repo: https://github.com/davidahines/no_master
我尝试删除HEAD,ORIG_HEAD和FETCH_HEAD,但似乎仍然无法收到此错误。
我认为我需要做的是以某种方式绕过此检查,或者在refs文件夹中找到另一个头但我在jgit中找不到它。
我目前无法访问客户的回购,因为它是封闭源代码。
答案 0 :(得分:0)
问题是jgit不支持/ home / username的波形符快捷方式,一旦删除它就有效。