Git diff output to file preserve coloring

Git

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

Try:

git diff --color > foo.txt

Then later issue:

cat foo.txt

Or:

less -R foo.txt

Solution 2 - Git

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

git diff > 20150203_someChanges.diff

Thanks @Monsingor

Solution 3 - Git

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

Solution 4 - Git

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

Solution 5 - Git

Vim colors files containing git diff's beautifully.

git diff

Solution 6 - Git

I found an answer here: https://stackoverflow.com/questions/23107594/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

Solution 7 - Git

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

Solution 8 - Git

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

Solution 9 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRoRView Question on Stackoverflow
Solution 1 - GitralphtheninjaView Answer on Stackoverflow
Solution 2 - GitironhydeView Answer on Stackoverflow
Solution 3 - GitJulienView Answer on Stackoverflow
Solution 4 - Gitsk8asd123View Answer on Stackoverflow
Solution 5 - GitRose PerroneView Answer on Stackoverflow
Solution 6 - GitamaslennView Answer on Stackoverflow
Solution 7 - GitAbhijeetView Answer on Stackoverflow
Solution 8 - GitScott StenslandView Answer on Stackoverflow
Solution 9 - GitChoylton B. HigginbottomView Answer on Stackoverflow