Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 在diff中也使用逗号作为单词分隔符_Git_Diff - Fatal编程技术网

Git 在diff中也使用逗号作为单词分隔符

Git 在diff中也使用逗号作为单词分隔符,git,diff,Git,Diff,如何添加,作为git diff的单词分隔符--word diff 例如,我希望diff能够认识到这一点 function(A,B,C) -> function(A, B, C) 只添加了空格,而不是替换整行。使用--word diff regex: --word-diff-regex=<regex> Use <regex> to decide what a word is, instead of considering runs

如何添加
作为git diff的单词分隔符--word diff

例如,我希望diff能够认识到这一点

function(A,B,C) -> function(A, B, C)
只添加了空格,而不是替换整行。

使用
--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.
--word diff regex=
用来决定一个词是什么,而不是考虑跑步
将非空白作为一个单词。也意味着--diff一词,除非
已启用。
的每个非重叠匹配项都被视为一个单词。
这些匹配之间的任何内容都被视为空白和空白
为查找差异而忽略(!)。你可能想
将|[^[:space:]追加到正则表达式以确保
它匹配所有非空白字符。包含
换行符在换行符处被自动截断(!)。
regex还可以通过diff驱动程序或配置进行设置
选项,请参阅gitattributes(1)或git配置(1)。明确地给出
覆盖任何差异驱动程序或配置设置。差异驱动程序
覆盖配置设置。

我从未使用过它,但我想,
git diff--word diff regex=“[^[:space:],]+”
可能会起作用。

您也可以尝试
-w
/
--忽略所有空格
,尽管这可能会忽略比您喜欢的更多的空格。

除了KurzedMetal的答案之外:如果没有引号,它的效果会更好,因为它在点击TAB时不会破坏我的bashs自动完成功能


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

-b忽略了一点空白。如果我指定--word diff,而不是每次都必须指定regex,那么在git config中如何设置它,默认情况下使用这个regex,我会忽略它。回答我自己的问题:
git config--global diff.wordRegex[^[:space:],]+
唯一的缺陷是它不会显示添加/删除的逗号。也可以使用
--word diff regex=“[^[:space:],]+|[,]+”
来查看答案,答案是逗号和空格。仅对于逗号,我们使用
--word diff regex='[^,]+'