当我运行以下示例代码时:
public static void main(String[] args) throws IOException, GitAPIException {
Git git = new Git(new FileRepository(PATH_TO_REPO);
BlameCommand blameCommand = git.blame();
blameCommand.setStartCommit(git.getRepository().resolve("HEAD"));
blameCommand.setFilePath(PATH_TO_FILE);
BlameResult blameResult = blameCommand.call();
Set<Integer> iterations = new HashSet<>();
Set<Integer> gitSourceLines = new HashSet<>();
RawText rawText = blameResult.getResultContents();
for (int i = 0; i < rawText.size(); i++) {
iterations.add(i);
gitSourceLines.add(blameResult.getSourceLine(i));
System.out.println("i = " + i +
", getSourceLine(i) = " + blameResult.getSourceLine(i));
}
System.out.println("iterations size: " + iterations.size());
System.out.println("sourceLines size: " + gitSourceLines.size());
}
Run Code Online (Sandbox Code Playgroud)
该文件的结果如下:
i = …Run Code Online (Sandbox Code Playgroud)