0

Is there a way to save the colored output from a git show?

I saw the post about using a different editor. But that is a lot more than what I'm trying to do. I just want to capture a report that is visually easy to read.

2 Answers 2

1

Prefix your git command like so

 git -c color.status=always 

And colour will always be produced

Edit 2023:

Above had not worked, but below had:

if you want color codes in your redirected output, you can instead pass a --color flag to the Git command to force it to use color codes

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

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

Comments

1

You could use VIm with syntax highlight and the TOhtml command.

git show COMMIT:FILE.abc | vim -c "set filetype=abc" -c "TOhtml" -c "x git_show.html" -c "qa!" -

Where:

  • FILE.abc is the file which will be shown in the past version defined by COMMIT hash code

Note:

  1. The html result file will be named git_show.html and will be located in the current folder.
  2. You must pass the correct filetype replacing abc to another file extension, like cpp or java.

Dissecting this long piped command:

set filetype=abc : activates the syntax highlight conforming to the abc type
TOhtml               : makes VIm export the highlighted opened file to a HTML
x git_show.html  : x acts like wq, saving the file as git_show.html and then closing the current buffer.
qa!                      : force VIm to exit without saving anything else
-  (trailing)           : makes VIm read from stdin

Comments

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.