Also use comma as a word separator in diff

北战南征 提交于 2019-12-03 09:11:05

问题


How can I add , as a word separator for git diff --word-diff?

For instance I would like the diff to recognize that

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

only has added the spaces instead of replacing the whole line.


回答1:


Use --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.

I never used it but i guess that git diff --word-diff-regex="[^[:space:],]+" may work.




回答2:


In addition to KurzedMetal's answer: without the quotes it works even better since it doesn't break my bashs autocompletion when hitting TAB.

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




回答3:


You can also try -w/--ignore-all-space, although that may ignore more whitespace than you like.



来源:https://stackoverflow.com/questions/10482773/also-use-comma-as-a-word-separator-in-diff

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!