2

我试图通过提供提交 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());

上面的代码不起作用,有人可以找出这里出了什么问题或任何其他方法来让它工作吗?

4

1 回答 1

0

也许这个代码示例在使用 IndexDiff 时会有所帮助。

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);
于 2012-02-24T08:43:44.180 回答