我在使用 git diff --word-diff 时遇到问题。问题是当 diff 获取没有换行符的文件(单行文件)时,它逐行区分。我想逐字区分。
当我比较没有换行符的文件时,会发生以下情况:
git diff -a --word-diff=plain file1 file2
diff --git a/file1 b/file2
index 3526254..0515a63 100644
--- a/file1
+++ b/file2
@@ -1 +1 @@
[- a a a a a a a a a a-]
No newline at end of file
{+a a a a a ab a a a a+}
如果我在文件末尾添加换行符,一切都会按预期工作:
git diff -a --word-diff=plain file1 file2
diff --git a/file1 b/file2
index 1756d83..1ec45b9 100644
--- a/file1
+++ b/file2
@@ -1,2 +1,2 @@
a a a a a [-a -]{+ab +}a a a a