2012-05-07 138 views

回答

29

使用--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:],]+"工作。

+0

它的工作:-) – oberlies

+0

不知道如何设置它在混帐配置,默认使用这个表达式,当我指定--word-DIFF而不是我每次都指定正则表达式。 – sibaz

+1

回答了我自己的问题:'git config --global diff.wordRegex [^ [:space:],] +' – sibaz

1

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

+0

-b忽略少许空格 –

9

除了KurzedMetal的回答:没有引号,它的效果更好,因为它不会打击TAB时我的bash自动完成。

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