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

发布于 2024-07-19 14:27:43 字数 322 浏览 4 评论 0原文

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

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

编辑

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

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 技术交流群。

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

发布评论

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

评论(3

佼人 2024-07-26 14:27:43

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.

懒猫 2024-07-26 14:27:43

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

我已经在 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.

有深☉意 2024-07-26 14:27:43

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

Git diff 支持 --word-diff 选项,该选项几乎可以完成此上下文中问题所要求的任务。

--word-diff 支持多种模式(即 colorplainporcelain)。 对于乳胶和长句子的目的,对我来说最好的选择是 --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

其中 - 行将被涂成红色,并且+ 行将被着色为绿色)

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 (namely color, plain and porcelain). 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

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

to

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

then git diff --word-diff=porcelain will give:

 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

(where the - line will be coloured red, and the + line will be coloured green)

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