Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git diff output to file preserve coloring

Tags:

git

People also ask

How does git diff change if you add the -- color option to the command?

git diff --color-words git diff also has a special mode for highlighting changes with much better granularity: ‐‐color-words . This mode tokenizes added and removed lines by whitespace and then diffs those. Now the output displays only the color-coded words that have changed.

What do the colors mean in git diff?

The colour of a particular file indicates the file change type: Green - ADDED (a new file was added) Blue - MODIFIED (an existing file was modified) Brown - COPIED (an existing file was copied to create a new file) Brown - MOVED (an existing file was moved to a new path)

What does git diff -- staged do?

git diff --staged will only show changes to files in the "staged" area. git diff HEAD will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same. Follow this answer to receive notifications.


Try:

git diff --color > foo.txt

Then later issue:

cat foo.txt

Or:

less -R foo.txt

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.


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


Vim colors files containing git diff's beautifully.

git diff