1 回答
TA贡献1811条经验 获得超5个赞
代码已更改为
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b );
}
public String toString(){
return this.string.toString();
}
};
RevCommit headCommit = getHeadCommit(repository);
RevCommit diffWith = headCommit.getParent(0);
try (DiffFormatter diffFormatter = new DiffFormatter(output)) {
diffFormatter.setRepository(repository);
for (DiffEntry entry : diffFormatter.scan(diffWith, headCommit)) {
diffFormatter.format(diffFormatter.toFileHeader(entry));
}
String strings = output.toString();
System.out.println(strings);
这是一条很长的路,但它证明了它可以做到 这现在已经将差异存储到字符串中
strings
添加回答
举报