本文最后更新于 143 天前,其中的信息可能已经有所发展或是发生改变。
问题描述
这样的时候合并信息是正常的
private static String getString(Blob curCommitBlob, Blob givenCommitBlob) {
byte[] curFileContent = new byte[0];
if (curCommitBlob != null) {
curFileContent = curCommitBlob.getContent().getBytes(StandardCharsets.UTF_8);
} else {
curFileContent = new byte[0];
}
byte[] givenFileContent = null;
if (givenCommitBlob != null) {
givenFileContent = givenCommitBlob.getContent().getBytes(StandardCharsets.UTF_8);
} else {
givenFileContent = new byte[0];
}
byte[] head = "<<<<<<< HEAD\n".getBytes(StandardCharsets.UTF_8);
byte[] body = "=======\n".getBytes(StandardCharsets.UTF_8);
byte[] feet = ">>>>>>>\n".getBytes(StandardCharsets.UTF_8);
ByteArrayOutputStream str = new ByteArrayOutputStream();
try {
str.write(head);
str.write(curFileContent);
str.write(body);
str.write(givenFileContent);
str.write(feet);
} catch (IOException e) {
throw new RuntimeException(e);
}
return str.toString();
}
这样就不正常了
private static String getString(Blob curCommitBlob, Blob givenCommitBlob) {
String curFileContent = null;
if (curCommitBlob != null) {
curFileContent = curCommitBlob.getContent();
} else {
curFileContent = "";
}
String givenFileContent = null;
if (givenCommitBlob != null) {
givenFileContent = givenCommitBlob.getContent();
} else {
givenFileContent = "";
}
return "<<<<<<< HEAD\n" +
curFileContent + "\n" +
"=======\n" +
givenFileContent + "\n" +
">>>>>>>";
}
这样写在我本地是这个格式
但是在评分机上会变成,多了一行回车!是不是很奇怪
<<<<<<< HEAD
Another wug.
=======
This is not a wug.
>>>>>>>
所以我最终的版本跑起来是这样,到现在依旧困惑
<<<<<<< HEAD
Another wug.
=======
This is not a wug.>>>>>>>