有没有办法逐句而不是逐行比较文件?

问题描述 投票:0回答:3

只是想让 diff 更好地处理某些类型的文档。例如,使用 LaTeX,我可能有一个很长的段落,严格来说只有一行,但如果只更改一个句子,我不想看到整个段落。特别是如果我正在运行某种版本控制并且合著者与我编辑同一段落(但不是同一句子)。我不希望这表现为冲突。

这是次要问题。主要问题是我是否可以使用 diff 逐句查看。谢谢。

编辑

wdiff
几乎完美。但是是否有一个等效的合并,就像
diff
diff3
一样?

diff word-diff
3个回答
6
投票

wdiff
将为您提供逐字差异而不是逐行差异。我不知道有任何逐句差异程序。


2
投票

在比较文件之前对文件进行预处理。编写一个脚本,每行写一个句子,任何逐行比较程序都可以工作。

我在 C 令牌级别上完成了此操作,以比较 C 代码,以便绝对确保我的 CVS 合并是正确的。


0
投票

14 年后回答,以防有人特别考虑到 git diff 遇到这个问题(这似乎是原始问题中隐含的意图)。

Git diff 支持

--word-diff
选项,该选项几乎可以满足问题在这种情况下提出的要求。

--word-diff
支持多种模式(即
color
plain
porcelain
)。对于乳胶和长句子的目的,对我来说最好的选择是
--word-diff=porcelain
。这会遍历句子,直到找到差异,然后将差异单独输出为删除/添加的对,然后继续执行句子。

换句话说,如果您将乳胶从

 This is a common part of the sentence, and previously we had this and the rest is common again

This is a common part of the sentence, but then we changed this part and the rest is common again

然后

git diff --word-diff=porcelain
将给出:

 This is a common part of the sentence,
-and previously we had this
+but then we changed this part
 and the rest is common again

(其中

-
线将为红色,
+
线将为绿色)

© www.soinside.com 2019 - 2024. All rights reserved.