How do I split words on punctuation in git diff?

I’ve have some luck with the following command:

git diff --color-words='[^][<>()\{},.;:?/|\\=+*&^%$#@!~`"'\''[:space:]]+|[][<>(){},.;:?/|\\=+*&^%$#@!~`"'\'']'

but it doesn’t seem to negate the square brackets properly in the first character class.

  • VCS independent diff
  • How exactly does subversion store files in the repository?
  • Git revert all changes that are ignored by git diff -w
  • is there a way to pipe the git or Mercurial diff output to a GUI Diff tool?
  • How to make git diff treat a file as binary _only sometimes_
  • PhpStorm - advanced settings for diff viewer
  • I’ve tried this:

    git diff --color-words='[^\]\[<>()\{},.;:?/|\\=+*&^%#@!~`"'\''[:space:]]+|[\]\[<>(){},.;:?/|\\=+*&^%#@!~`"'\'']'
    

    in order to make the square brackets literal, but it fails with the message fatal: Invalid regular expression.

    Edit:

    The output I get is like so:

    foobarfo]ob[ar

    But what I’m after is:

    fo]oob[ar

  • git and visual studio 2010 express
  • Can't push local git branch upstream
  • git pull not working
  • TeamCity's git checkout different from local git checkout
  • Git fails when pushing commit to github
  • Git/rsync mix for projects with large binaries and text files
  • One Solution collect form web for “How do I split words on punctuation in git diff?”

    With word diff you will always see the word you removed next to the new one.

    This is why you have the word before your new change.

    Read this question, very detailed answer:

    Filtering a diff with a regular expression

    Git Baby is a git and github fan, let's start git clone.