Git - Color words excluding {}

后端 未结 2 624
一生所求
一生所求 2021-01-11 18:21

I am using git with --color-words to view my diff. In my diff, it shows that I removed

{{ljcount}}   Changes
<         


        
相关标签:
2条回答
  • 2021-01-11 19:04

    From git help diff:

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

    The following expression will make a word be any string of characters and underscore, or any non-whitespace character.

    $ git diff --color-words --word-diff-regex='\\w+|[^[:space:]]'
    
    0 讨论(0)
  • 2021-01-11 19:26

    Since you already use --color-words, you don't need to supply --word-diff-regex separately, the first option accepts a regex:

    --color-words[=<regex>]
    

    Equivalent to --word-diff=color plus --word-diff-regex=<regex> (if a regex was specified).

    A regex that works particularly well for me is:

    $ git diff --color-words='\w+|.'
    
    0 讨论(0)
提交回复
热议问题