Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert the output of `git diff --color-words` to HTML?

Tags:

git

diff

For working with text that is prose, stored in plain text, I really like the output of git diff --color-words, but I don't like the way it is dependent on ANSI terminal escape sequences. I'd like to get output that I can use to turn into HTML, some kind of user-friendly raw character display, or to generate statistics on the differences between the two files.

I prefer Perl (including CPAN), but would settle for pretty much anything.

like image 519
singingfish Avatar asked Sep 15 '09 07:09

singingfish


People also ask

What do the colors mean in git diff?

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) Red - REMOVED (an existing file was removed)

What does git diff output?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

How to interpret git diff?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.

What@@ means in git diff?

The fourth line shows you symbol @@ and symbols ahead of it. They are called chunks. Chunks in git diff define the change' summary. In our image below the following chunk can be seen @@ -1,2 +1 @@ This means that lines one and two were changed in the first file and line one was changed in the second file.


1 Answers

This question asks about converting ANSI escape sequences into HTML color directives, and the accepted answer is a link to the Perl module HTML::FromANSI, in CPAN.

like image 108
caf Avatar answered Sep 25 '22 17:09

caf