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?

Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
  • Try [ConEmu](https://github.com/Maximus5/ConEmu) a console for Windows and use the option "copy as html". Also you can try [NppExport plugin for Notepad++ 32-bit](https://www.addictivetips.com/windows-tips/nppexport-for-notepad-export-highlighted-code-in-html-rtf-format/) 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. – Mark Mikofski Jan 29 '18 at 17:40

2 Answers2

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.

match
  • 10,388
  • 3
  • 23
  • 41
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?

kostix
  • 51,517
  • 14
  • 93
  • 176
  • i wish it was easier, some advanced scenarios are only supported by git in its latest versions (no tool around knows them): https://stackoverflow.com/questions/48350398/the-original-file-that-was-split-in-2-other-files-is-there-a-way-in-git-to-see so git output is my only source, which i cannot save, hence the question – Trident D'Gao Jan 29 '18 at 17:34
  • @AlekseyBykov, updated my answer to also mention direct/wrapped support for ANSI color code sequences by Windows consoles. – kostix Jan 29 '18 at 17:35
  • 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 – Trident D'Gao Jan 29 '18 at 17:36
  • 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 – Trident D'Gao Jan 29 '18 at 17:40
  • @AlekseyBykov quick googling yields [this](https://answers.microsoft.com/en-us/office/forum/office_2010-word/how-can-i-import-an-html-page-into-word-while/329225f2-7d14-4e6b-a284-9bcb1cdac8c1)—see the comment at the bottom re. saving the html as `.mht` in IE and then opening the latter with MSWord. – kostix Jan 29 '18 at 17:50