Git – Color words excluding {}

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


And that I added:

  • Git push results in fatal: protocol error: bad line length character: This
  • Git keeping certain commits out of pull requests
  • mvn release:perform fails from a git branch: does the pom.xml need to have same version on master?
  • Set username and email for msysgit portable
  • Can I merge two Git repositories with similar content, but not sharing any ancestry?
  • How to validate and display error for git commit message?
  • <b>{{skills_limits}}</b>&nbsp;&nbsp;&nbsp;Changes

    This is larger than what I would like it to be (I want the word boundary to be at the {}). I tried playing around with --word-diff-regex, but I couldn’t find a regex to make it work. How can I achieve this result?

  • GIT copy file preserving history
  • TeamCity prevent simultaneous branch builds
  • Doxygen and git for automated file version information
  • Remote Git Repository in document root
  • gitlab-shell -> git push -u origin master -> fatal: The remote end hung up unexpectedly
  • 'git' is not recognized as an internal or external command
  • 2 Solutions collect form web for “Git – Color words excluding {}”

    From git help diff:

           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:]]'

    Since you already use --color-words, you don’t need to supply --word-diff-regex separately, the first option accepts a 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+|.'
    Git Baby is a git and github fan, let's start git clone.