[Solved] Git diff output to file preserve coloring

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

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

Enquirer: RoR

||

Solution #1:

Try:

git diff --color > foo.txt

Then later issue:

cat foo.txt

Or:

less -R foo.txt
Respondent: ralphtheninja

Solution #2:

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

git diff > 20150203_someChanges.diff

Thanks @Monsingor

Respondent: ironhyde

Solution #3:

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

Respondent: Julien

Solution #4:

To expand on @Gabe’s answer.

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

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

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

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

Respondent: sk8asd123

Solution #5:

Vim colors files containing git diff’s beautifully.

git diff

Respondent: Rose Perrone

Solution #6:

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

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

Respondent: amaslenn

Solution #7:

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).

Respondent: Abhijeet

Solution #8:

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

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

install aha using above then issue

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

firefox  ~/cool_colorized.html
Respondent: Scott Stensland

Solution #9:

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

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published. Required fields are marked *

New ride at Perth's Adventure World a ‘swing on steroids’ - Australasian Leisure Management npp pharma the truth about anabolic steroid drugs and professional sports