how would you convert the output of git diff --word-diff
to html (using Python preferably)?
-
Have you looked at http://stackoverflow.com/questions/2013091/coloured-diff-to-html and http://stackoverflow.com/questions/2053657/git-diff-to-html? – Go Dan Oct 11 '11 at 02:04
-
1Yes, but word-diff seems less hacky to work with (compared to color-words), especially with the porcelain output mode. – Alex Oct 11 '11 at 02:11
2 Answers
You can pipe a call to aha (a tool that converts colored terminal text to html). Something like this:
git diff --word-diff | aha
If you using debian, you can download it from this link: http://packages.debian.org/sid/aha Hope it helps.

- 1,469
- 1
- 11
- 19
-
Even though `git diff --word-diff` displays with colour, I had trouble getting `aha` to add the colour until I did `git diff --word-diff --color | aha`. – Jonathan W. Oct 03 '22 at 16:19
As mentioned in dvicino's answer, using aha
works well. In my case, I needed to additionally use --color
with git diff --word-diff
:
git diff --word-diff --color | aha
The need to use --color
is a little perplexing, because git diff --word-diff
makes coloured output without --color
. But apparently the output isn't sufficiently ANSI-coded for aha
to "adapt" it to HTML.
In my specific case, I'm using something more like the following, and it works exactly as expected.
git diff --word-diff --color [revisionhash] | aha --black --word-wrap > diff.html
(I'm adding a full answer in addition to my comment, because I was unable to find any answers that indicted that --color
is needed. Maybe it's a system-specific thing, but perhaps others will find this useful.)

- 135
- 1
- 9