有没有办法逐句而不是逐行比较文件?
只是想让 diff 更好地处理某些类型的文档。 例如,使用 LaTeX,我可能有一个很长的段落,严格来说只有一行,但如果只更改一个句子,我不想看到整个段落。 特别是如果我正在运行某种版本控制并且合著者与我编辑同一段落(但不是同一句子)。 我不希望这表现为冲突。
这是一个次要问题。 主要问题是我是否可以使用 diff 逐句查看。 谢谢。
编辑
wdiff
几乎是完美的。 但是是否有一个等效的合并,就像 diff
与 diff3
一样?
Just trying to get diff to work better for certain kinds of documents. With LaTeX, for example, I might have a long paragraph that is strictly just one line, but I don't want to see that entire paragraph if just a sentence is changed. Particularly if I'm running some kind of version control and a co-author edits the same paragraph (but not the same sentence) as me. I wouldn't want that to show up as a conflict.
That's a secondary question. The main question is whether I can use diff to look sentence-by-sentence. Thanks.
Edit
wdiff
is almost perfect. But is there a merge equivalent, as diff
has with diff3
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
wdiff
将为您提供逐字比较,而不是逐行。 我不知道有任何逐句差异程序。wdiff
will give you a word-by-word diff instead of line-by-line. I'm not aware of any sentence-by-sentence diff programs.在比较文件之前对文件进行预处理。 编写一个脚本,每行写一个句子,任何逐行比较程序都可以工作。
我已经在 C 令牌级别上完成了此操作,以比较 C 代码,以便绝对确保我的 CVS 合并是正确的。
Preprocess the files before diffing them. Write a script to write one sentence per line and any line by line diff program will work.
I have done this on a C token level for diffing C code in order to make absolutely sure my CVS merge was correct.
14 年后回答,以防有人特别想到 git diff 遇到这个问题(这似乎是原始问题中隐含的意图)。
Git diff 支持
--word-diff
选项,该选项几乎可以完成此上下文中问题所要求的任务。--word-diff
支持多种模式(即color
、plain
和porcelain
)。 对于乳胶和长句子的目的,对我来说最好的选择是--word-diff=porcelain
。 它会遍历句子,直到找到差异,然后将差异单独输出为删除/添加的对,然后继续处理句子。换句话说,如果您将乳胶从 更改为 ,
那么
git diff --word-diff=porcelain 将会给出:(
其中
-
行将被涂成红色,并且+
行将被着色为绿色)Answering 14 years later in case anyone comes across this with git diff in mind specifically (which seems to have been the implied intend in the original question).
Git diff supports a
--word-diff
option, which does pretty much what the question is asking in this context.--word-diff
supports a number of modes (namelycolor
,plain
andporcelain
). For the purposes of latex and long sentences, for me the best option would be--word-diff=porcelain
. This walks through the sentence until it finds a difference, and then outputs the difference separately as a removed/added pair, before continuing on with the sentence.In other words, if you changed your latex from
to
then
git diff --word-diff=porcelain
will give:(where the
-
line will be coloured red, and the+
line will be coloured green)