How to improve git's diff highlighting?

后端 未结 3 599
时光说笑
时光说笑 2020-12-14 20:59

The output of git diff is optimized for code which tends to be one statement per line whereas text can (if authors like me are too lazy to use line breaks) caus

3条回答
  •  不思量自难忘°
    2020-12-14 21:26

    You could use the --word-diff[=] option to make it easier to see which words have changed within a line. This is described in the man page as

    Show a word diff, using the to delimit changed words. By default, words are delimited by whitespace; see --word-diff-regex below. The defaults to plain, and must be one of:

    • color – Highlight changed words using only colors. Implies --color.

    • plain – Show words as [-removed-] and {+added+}. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous.

    • porcelain – Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/-/` ` character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde ~ on a line of its own.

    • none – Disable word diff again.

    Note that despite the name of the first mode, color is used to highlight the changed parts in all modes if enabled.

提交回复
热议问题