Git diff 输出到文件保留着色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9706492/
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-10 13:12:12  来源:igfitidea点击:

Git diff output to file preserve coloring

git

提问by RoR

Is it possible to do git diffand save the output to a file with the coloring somehow?

是否可以以git diff某种方式将输出保存到带有着色的文件中?

I know how to do git diff > filename.rtf- which saves to a file, but I'd like to preserve the coloring.

我知道该怎么做git diff > filename.rtf- 保存到文件中,但我想保留颜色。

回答by ralphtheninja

Try:

尝试:

git diff --color > foo.txt

Then later issue:

然后后面的问题:

cat foo.txt

Or:

或者:

less -R foo.txt

回答by ironhyde

Save the file with a .diff extension and open it in Notepad++ or Vim or SublimeText.

使用 .diff 扩展名保存文件并在 Notepad++ 或 Vim 或 SublimeText 中打开它。

git diff > 20150203_someChanges.diff

Thanks @Monsingor

谢谢@Monsingor

回答by Julien

Open the output diff file in Sublime Text 2. It shows the diff colors.

Sublime Text 2 中打开输出差异文件。它显示差异颜色。

回答by sk8asd123

To expand on @Gabe's answer.

扩展@Gabe 的回答。

You can pipe the output to an ansi to html converter bash script and direct that output to an html file:

您可以将输出通过管道传输到 ansi 到 html 转换器 bash 脚本并将该输出定向到一个 html 文件:

git diff --color|./ansi2html.sh > changes.html

of course html can be viewed by any browser so output can be read in Windows etc.

当然,任何浏览器都可以查看 html,因此可以在 Windows 等中读取输出。

ansi2html code is here: http://www.pixelbeat.org/scripts/ansi2html.sh

ansi2html 代码在这里:http://www.pixelbeat.org/scripts/ansi2html.sh

回答by Rose Perrone

Vim colors files containing git diff's beautifully.

Vim 为包含 git diff 的文件着色精美。

git diff

混帐差异

回答by amaslenn

I found an answer here: Color output of specific git command.

我在这里找到了答案:特定 git 命令的颜色输出

You can pass -c color.ui=alwaysto any gitcommand and it will keep coloring on redirection. For example: git -c color.ui=always status > file

您可以传递-c color.ui=always给任何git命令,它会在重定向时保持着色。例如:git -c color.ui=always status > file

回答by Abhijeet

git remote add -f b path/to/repo_b.git
git remote update
git diff master remotes/b/master > foo.txt

Differences extracted in '*.txt' files are easily read by SublimeText2 without the need to set (via View -> Syntax -> Diff).

SublimeText2 可以轻松读取在 '*.txt' 文件中提取的差异,无需设置(通过 View -> Syntax -> Diff)。

回答by Scott Stensland

to allow any colorized terminal text ... git diff or any other ... to be viewable from a browser

允许任何彩色终端文本...... git diff 或任何其他......可以从浏览器中查看

sudo apt-get install aha  #  https://github.com/theZiz/aha

install ahausing above then issue

aha使用上面安装然后发出

git diff --color mysourcefile  | aha > ~/cool_colorized.html

firefox  ~/cool_colorized.html

回答by Choylton B. Higginbottom

You could upload to GitHub and provide a link to the relevant commit.

您可以上传到 GitHub 并提供相关提交的链接。