How can I visualize per-character differences in a unified diff file?

后端 未结 7 1933
庸人自扰
庸人自扰 2020-11-30 17:13

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

7条回答
  •  野性不改
    2020-11-30 17:58

    Here are some versions with less noisy output than git diff --word-diff-regex= and that require less typing than, but are equivalent to, git diff --color-words --word-diff-regex=.

    Simple (does highlight space changes):

    git diff --color-words
    

    Simple (highlights individual character changes; does not highlight space changes):

    git diff --color-words=.
    

    More complex (does highlight space changes):

    git diff --color-words='[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+'
    

    In general:

    git diff --color-words=
    

    where is a regexp defining "words" for the purpose of identifying changes.

    These are less noisy in that they color the changed "words", whereas using just --word-diff-regex= surrounds matched "words" with colored -/+ markers.

提交回复
热议问题