1

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?

1
  • Try ConEmu a console for Windows and use the option "copy as html". Also you can try NppExport plugin for Notepad++ 32-bit it works really well at copy-&-paste with formatting - try the "Copy All Formats" option and try to paste in a doc, email, or rtf editor - the editor must be able to support formatting so it would never work with text only. Commented Jan 29, 2018 at 17:40

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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?

5 Comments

i wish it was easier, some advanced scenarios are only supported by git in its latest versions (no tool around knows them): stackoverflow.com/questions/48350398/… so git output is my only source, which i cannot save, hence the question
@AlekseyBykov, updated my answer to also mention direct/wrapped support for ANSI color code sequences by Windows consoles.
windows console indeed supports colors while displaying output, my question was about preserving this output to an editable file, so i can go through it and edit it
html isn't the most convenient format to edit, but i appreciate your answer, the git part of the question is clear, need to find a tool that can save to doc or rtf
@AlekseyBykov quick googling yields this—see the comment at the bottom re. saving the html as .mht in IE and then opening the latter with MSWord.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.