小编Moa*_*oaz的帖子

使用JGit怪时结果错误

当我运行以下示例代码时:

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)

java git blame jgit

5
推荐指数
0
解决办法
275
查看次数

标签 统计

blame ×1

git ×1

java ×1

jgit ×1