这篇文章用的是老版本的jgit。
新的jgit这样用:
package com.aliyun.qa;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.revwalk.RevCommit;
public class JgitDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File rootFile = new File("/home/wuhe.jyh/V7FHDmaster/yunos/packages/apps/Contacts/.git");
FileRepository repo = new FileRepository(rootFile);
Git git = new Git(repo);
try {
for(RevCommit rc : git.log().call()) {
System.out.println("id: " + rc.getId().toString());
System.out.println("author name: " + rc.getAuthorIdent().getName());
// 注意:如果这里写成int,就错掉啦!!!
long commitTime = rc.getCommitTime();
System.out.println("commitTime :" + commitTime);
long time = commitTime * 1000;
Date date = new Date();
date.setTime(time);
System.out.println("date: " + date);
}
} catch (NoHeadException e) {
e.printStackTrace();
} catch (GitAPIException e) {
e.printStackTrace();
}
}
}
转载于:https://blog.51cto.com/memory/1295030