如何在统一的差异文件中可视化每个字符的差异? [英] How can I visualize per-character differences in a unified diff file?
问题描述
假设我得到了一个用 git format-patch
创建的补丁.该文件基本上是带有一些元数据的统一差异.如果我在 Vim 中打开文件,我可以看到哪些行被修改,但我看不到更改行中哪些 字符 不同.有谁知道一种方法(在 Vim 或其他一些在 Ubuntu 上运行的免费软件中)来可视化每个字符的差异?
Say I get a patch created with git format-patch
. The file is basically a unified diff with some metadata. If I open the file in Vim, I can see which lines have been modified, but I cannot see which characters in the changed lines differ. Does anyone know a way (in Vim, or some other free software that runs on Ubuntu) to visualize per-character differences?
在执行 vimdiff a b
时可视化每个字符差异的反例.
A counter example where per-character diff is visualized is when executing vimdiff a b
.
更新时间为 2010 年 11 月 12 日星期五 22:36:23 UTC
diffpatch 对以下情况很有帮助重新处理单个文件.
更新 2016 年 6 月 16 日星期四 17:56:10 UTC
查看 git 2.9 中的差异突出显示.这个脚本正是我最初想要的.
Check out diff-highlight in git 2.9. This script does exactly what I was originally seeking.
推荐答案
鉴于您在问题中对 Vim 的引用,我不确定这是否是您想要的答案 :) 但 Emacs 可以做到这一点.打开包含差异的文件,确保您处于 diff-mode
(如果文件名为 foo.diff
或 foo.patch
> 这会自动发生;否则输入 Mx diff-mode
RET),转到您感兴趣的大块头并点击 Cc Cb 用于 refine-hunk
.或者用 M-n 一次一大块地浏览文件;这将自动进行精炼.
Given your references to Vim in the question, I'm not sure if this is the answer you want :) but Emacs can do this. Open the file containing the diff, make sure that you're in diff-mode
(if the file is named foo.diff
or foo.patch
this happens automatically; otherwise type M-x diff-mode
RET), go to the hunk you are interested in and hit C-c C-b for refine-hunk
. Or step through the file one hunk at a time with M-n; that will do the refining automatically.
这篇关于如何在统一的差异文件中可视化每个字符的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!