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

一世执手 提交于 2019-12-02 17:50:36

git diff --color-words --no-index

According to a comment from Jefromi you can just use

git diff --color-words file1 file2

outside of git repositories too.

Git version 1.9.1:

git diff --word-diff=color fileA fileB

you can say git diff --color=always --color-words, which will give you the color escape codes in the output. you are going to have some shell to interpret the color codes though …

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!