如何在 Git 存储库外使用`git diff --color-words`?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5637311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:20:30  来源:igfitidea点击:

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

gitcolorsdiffwordword-diff

提问by Vi.

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

我怎样才能得到像 in 一样的输出 git diff --color-words,但在 Git 之外?

Closest thing is wdiff -t, but it underlines/inverts things instead of using green/red colours and does not allow specifying my whitespace regex.

最接近的是wdiff -t,但它强调/反转事物而不是使用绿色/红色,并且不允许指定我的空白正则表达式。

回答by Vi.

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

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

回答by Thomas

According to a comment from Jefromi you can just use

根据 Jefromi 的评论,您可以使用

git diff --color-words file1 file2

outside of git repositories too.

在 git 存储库之外。

回答by JellicleCat

Git version 1.9.1:

Git 版本 1.9.1:

git diff --word-diff=color fileA fileB

git diff --word-diff=color fileA fileB

回答by Pierre-Olivier Vares

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

如果我在 git 存储库 (git v2.3.3) 中:

  • git diff --color-wordsdoesn't work (no output)
  • git diff --no-indexdoesn't accept --color-wordsnor --colorarguments
  • git diff --color-words不起作用(无输出)
  • git diff --no-index不接受--color-words也不--color争论

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

使用 wdiff 是可能的,配置为使用颜色,而不是下划线:

wdiff -n \
  -w $'3[30;31m' -x $'3[0m' \
  -y $'3[30;32m' -z $'3[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)

来源:https: //www.gnu.org/software/wdiff/manual/html_node/wdiff-Examples.html(修改为使用前景色而不是背景色)

Hope it helps.

希望能帮助到你。

回答by knittl

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 …

你可以说git diff --color=always --color-words,这会给你输出中的颜色转义码。不过,您将有一些外壳来解释颜色代码……