我试图通过提供提交ID来获取所有提交的文件。
RevCommit commit = walk.parseCommit(ObjectId.fromString(objId));
FileTreeIterator fileTreeItr = new FileTreeIterator(repository);
Tree tree = new Tree(repository);
IndexDiff indexDiff = new IndexDiff(repository, commit.getId(), fileTreeItr);
System.out.println(indexDiff.getChanged());
System.out.println(indexDiff.getAdded());
以上代码无法正常工作,有人可以弄清楚这里有什么问题或任何其他方法让这个有用吗?
答案 0 :(得分:0)
使用IndexDiff时,也许这个code example会有所帮助。
IResource project = session.getLaunchedProject().getResource();
File gitDir = new File(project.getLocation().toFile().toString() + "/.git");
System.out.println("gitDir:" + gitDir);
Repository repository = new FileRepository(gitDir);
File workTree = repository.getWorkTree();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
WorkingTreeIterator fileTreeIterator =
new AdaptableFileTreeIterator(workTree, workspaceRoot);
IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator);