git diff --word-diff 与单行文件

发布于 2024-12-26 07:04:46 字数 587 浏览 1 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2025-01-02 07:04:46

我写信给 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文