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:

  • Some tricks for Git log
  • Know when a line of code was added to a GitHub repository
  • Git push failed, “Non-fast forward updates were rejected”
  • How do I undo this git configuration?
  • ldap authentication with gitblit 1.0
  • Process returned an error (exit code -3) in cake execution
  • <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?

  • Allowing all users to create a repo in TFS-GIT
  • What is the right way to merge branches when `git diff` shows changes but `git merge` does nothing
  • Parse git log file names to json
  • How to count number of commits per file pathname by author in a Git repository?
  • `git clean` removes ignored files by default?
  • Can reordering commits with git interactive rebase cause a conflict?
  • 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.