33

,git diff --word-diffの単語区切り文字として追加するにはどうすればよいですか?

たとえば、diffにそれを認識させたい

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

行全体を置き換えるのではなく、スペースを追加しただけです。

4

3 に答える 3

41

使用--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:],]+"はうまくいくと思います。

于 2012-05-07T13:32:09.167 に答える
11

KurzedMetal の回答に加えて、TAB を押しても bash のオートコンプリートが中断されないため、引用符がないとさらにうまく機能します。

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

于 2013-10-10T11:01:33.950 に答える