How can I use `git diff --color-words` outside a Git repository?

前端 未结 5 1342
既然无缘
既然无缘 2020-12-13 03:28

How can I get output like in git diff --color-words, but outside Git?

Closest thing is wdiff -t, but it underlines/inverts things instead

5条回答
  •  一个人的身影
    2020-12-13 04:20

    If I'm inside a git repository (git v2.3.3) :

    • git diff --color-words doesn't work (no output)
    • git diff --no-index doesn't accept --color-words nor --color arguments

    Using wdiff is possible, configured to use colors, rather than underlined :

    wdiff -n \
      -w $'\033[30;31m' -x $'\033[0m' \
      -y $'\033[30;32m' -z $'\033[0m' \
      … | less -R
    

    Source : https://www.gnu.org/software/wdiff/manual/html_node/wdiff-Examples.html (modified to use foreground colors rather than background colors)

    Hope it helps.

提交回复
热议问题