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

时间:2012-05-07 13:13:26

标签: git diff

如何将,添加为git diff --word-diff?

的单词分隔符

例如,我希望差异识别

function(A,B,C) -> function(A, B, C)

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

3 个答案:

答案 0 :(得分:31)

使用--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.

我从未使用过它,但我想git diff --word-diff-regex="[^[:space:],]+"可能有用。

答案 1 :(得分:9)

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

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

答案 2 :(得分:1)

您也可以尝试使用-w / --ignore-all-space,但这可能会忽略比您更喜欢的空格。