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.
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.
Try:
git diff --color > foo.txt
Then later issue:
cat foo.txt
Or:
less -R foo.txt
cat
the file from the command-line. (How else would you expect the colors to be preserved?)
Mar 14, 2012 at 17:20
Language --> D --> Diff
.) If you don't like default colors, change them in Settings --> Style Configurator --> Diff
. To copy paste with colors you can use a plugin (e.g. NppExport
) that allows exporting/copying into RTF or HTML.
Oct 22, 2015 at 22:31
Save the file with a .diff extension and open it in Notepad++ or Vim or SublimeText.
git diff > 20150203_someChanges.diff
Thanks @Monsingor
Open the output diff file in Sublime Text 2. It shows the diff colors.
diff.txt
for me, even with automatically detected "Diff" in the right bottom corner.
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
brew install gawk
. You'll also need brew install gnu-sed
.
Oct 30, 2015 at 19:53
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
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).
git remote rm remotes/b/master
to reset branch back to it's original state.
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