Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloured Git diff to HTML

I enjoy using git diff --color-words to clearly see the words that have changed in a file:

Screenshot

However I want to share that diff with someone without git or a colour terminal for that matter. So does anyone know of a tool or trick that can convert colour escaped terminal output into HTML?

like image 875
hendry Avatar asked Jan 06 '10 13:01

hendry


People also ask

What do the colors mean in git diff?

In the diff view there is a file tree showing all of the changes for that pull request. 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)

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.

Does GIT use diff?

Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.


2 Answers

wget "http://www.pixelbeat.org/scripts/ansi2html.sh" -O /tmp/ansi2html.sh chmod +x /tmp/ansi2html.sh git diff --color-words --no-index orig.txt edited.txt | \ /tmp/ansi2html.sh > 2beshared.html 

What I really needed was an ANSI to HTML converter. And I found a very decent one on http://www.pixelbeat.org/.

NOTE: You might not see any coloration unless you include --color or --color-words, probably because piping causes git diff to exclude colors.

NOTE 2: You may need to install gnu sed and awk, especially if you're on a Mac. Do so with brew install gnu-sed gawk. You may need to add them to your path manually, too, e.g. with ln -s /usr/local/Cellar/gnu-sed/4.2.2/bin/gsed /usr/local/bin/.

like image 179
hendry Avatar answered Sep 24 '22 01:09

hendry


download diff2html, extract it and convert diff to html with this command:

$ diff2html file1.txt file2.txt > diff-demo1.htm 

There is more ... take a look at this question.

Or after gitting:

git diff --color-words --no-index orig.txt /tmp/edited.txt > myfile 

download both ansifilter from this location. and use this command to convert myfile to html format

ansifilter -i myfile -H -o myfile2.html 

so ... this is exactly what you want ;)

like image 33
Michel Gokan Khan Avatar answered Sep 24 '22 01:09

Michel Gokan Khan