Trident D'Gao
Trident D'Gao

Reputation: 19690

How can I save color output from git to some text-processor file on Windows?

For the sake of doing better code reviews, I wish I could preserve the colors as I save stdout of git to some (not sure which one) text format file, so that I can open it for editing and enjoy the colors on Windows.

Is there a way to do it?

Upvotes: 1

Views: 553

Answers (2)

kostix
kostix

Reputation: 55483

What @match said — using --color=auto — combined with any tool which is able to interpret those "ANSI color sequences" and produce something which makes use of them.

Quick searching turns up this which looks like having been created for the exact purpose you're after.

(Well, and it appears that it's possible to set up plain Windows console in a way that mere running type on a file containing those escape sequences would make rendering of that file actually use colors.)

On the other hand, why do you need this? It's easier to use a tool which would present you with diff view etc, no?

BTW Git for Windows supports colors on the terminal just OK; may be you just have failed to somehow turn this on?

Upvotes: 0

match
match

Reputation: 11060

You can force git commands to always output the ansi color escape codes, even when being written to a file or piped to another command using the --color=alwaysflags. this results in output that looks like e.g.:

ESC[33mcommit 6d5ef5dd01337c83a27290e54ddc9a3370f9ffa4ESC[m

On linux if you save this to a file, you can view it in color with e.g.less -R - however you will need a Windows application capable of translating these codes back into color - I'm afraid I don't know anything about Windows to know what to suggest here.

Upvotes: 1

Related Questions