有时当我执行以下操作时:
BlameCommand blamer = new BlameCommand(repo);
ObjectId commitID = repo.resolve("head");
blamer.setStartCommit("head");
blamer.setFilePath(fileName);
BlameResult blame = blamer.call();
RevCommit commit = blame.getSourceCommit(0); //set to first line but can be random line of file
示例代码最后一行获取的commit为null
;它并不总是null
,只是在某些文件的某些行上。我怀疑这与 CR/LF 问题有关,因为我在 Windows 计算机上运行此代码,因此我尝试更改全局和存储库配置 core.autocrlf
值。我对 core.autocrlf 尝试了 true 和 false,但仍然遇到同样的问题。
当前使用: jgit-3.1.0.201310021548
最佳答案
我在 jgit-cookbook 添加了一个片段使用 BlameCommand,它在那里工作正常,在您的示例代码中 setStartCommit() 是错误的,它应该是 commitID。
以下内容对我有用:
BlameCommand blamer = new BlameCommand(repository);
ObjectId commitID = repository.resolve("HEAD");
blamer.setStartCommit(commitID);
blamer.setFilePath("README.md");
BlameResult blame = blamer.call();
关于java - jgitblame 文件的某些行具有 null 提交 shas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20036925/