git diff --word-diff 与单行文件
我在使用 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
I'm having trouble with git diff --word-diff. The thing is when diff gets file without newlines (one line file) it differrs it line by line. And I want to differ it word by word.
Here's what happens when I'm comparing files without newlines:
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+}
And if I add newline to the end of the files everything works as expected:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我写信给 GIT 团队,他们回答说这确实是一个错误。
他们还给我发送了该案例的补丁。
看起来它会在 1.7.9 中修复。
I wrote to GIT team and they answered that it is a bug indeed.
Also they send me a patch for that case.
Looks like it would be fixed in 1.7.9.