也可以使用逗号作为差异中的单词分隔符

Sed*_*rik 27 git diff

如何,为git diff --word-diff 添加单词分隔符?

例如,我希望差异识别出来

function(A,B,C) -> function(A, B, C)
Run Code Online (Sandbox Code Playgroud)

只添加了空格而不是替换整行.

Kur*_*tal 32

用途--word-diff-regex:

   --word-diff-regex=<regex>
       Use <regex> to decide what a word is, instead of considering runs
       of non-whitespace to be a word. Also implies --word-diff unless it
       was already enabled.

       Every non-overlapping match of the <regex> is considered a word.
       Anything between these matches is considered whitespace and
       ignored(!) for the purposes of finding differences. You may want to
       append |[^[:space:]] to your regular expression to make sure that
       it matches all non-whitespace characters. A match that contains a
       newline is silently truncated(!) at the newline.

       The regex can also be set via a diff driver or configuration
       option, see gitattributes(1) or git-config(1). Giving it explicitly
       overrides any diff driver or configuration setting. Diff drivers
       override configuration settings.
Run Code Online (Sandbox Code Playgroud)

我从来没用过它,但我猜这git diff --word-diff-regex="[^[:space:],]+"可能有用.

  • 唯一的缺陷就是它不会显示添加/删除的逗号.要查看它们,请使用`--word-diff-regex ="[^ [:space:],] + | [,] +"` (6认同)
  • 回答了我自己的问题:`git config --global diff.wordRegex [^ [:space:],] +` (2认同)

Kit*_*tze 10

除了KurzedMetal的答案:没有引号它更有效,因为它不会在击中TAB时破坏我的bashs自动完成.

git diff --word-diff-regex=[^[:space:],]+