61

I'm looking for a "diff to html" program, which would generate a static html page from a given diff/patch file.

I've googled for it of course, but apart from some scripts I've found there's no "real project" (e.g. no package in Debian/Ubuntu).

Have I missed something? Can you recommend anything?

blueyed
  • 27,102
  • 4
  • 75
  • 71
  • 1
    https://diff2html.xyz/ looks like it would answer your question (for anyone else looking) – scp Jul 28 '16 at 02:08

10 Answers10

28

You can use diff2html.py that is able to create a side-by-side diff in a static html page, from an unified diff input. The script is written in python.

cat foo.diff | python diff2html.py > foo.html
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
zer0
  • 281
  • 3
  • 2
25

pygments has syntax highlighting for diff (and for lots of other languages), and can be used as a library or a command-line program. Is that the sort of thing you're looking for? If not please clarify the question...

puetzk
  • 10,534
  • 3
  • 28
  • 32
  • 2
    Pygments is cool, it's too bad they don't support side by side diff rendering. – icco Jan 17 '10 at 04:46
  • 13
    This was useful for me: `diff -U9999999 -y file_before.php file_after.php | pygmentize -l diff -f html -O full -o file_diff.html` – jwhitlock Sep 27 '10 at 15:32
  • 1
    @jwhitlock excellent! Thanks a lot. I had to select `-u` instead of `-y` (side by side) though, otherwise diff was complaining of "conflicting output style options". – Christophe Muller Feb 09 '15 at 10:05
19

Something along the lines of:

vim test.diff -c TOhtml -c ":saveas test.html" -c ":q" -c ":q"

works well, and you can change the color-scheme of the diff by changing the color scheme in vi.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Daniel Zinn
  • 316
  • 2
  • 3
10

http://www.sourceforge.net/projects/diff2html

  • 1
    Tool reads diff output from standard in. But: it requires both files on command line as well: "Pipe stdout of diff to stdin of /home/fapgg/diff2html (slightly faster): diff file1 file2 | /home/fapgg/diff2html [options] file1 file2", i.e. it will not work on existing diff/patch file – Gerrit Griebel Sep 11 '19 at 14:31
  • As NPM module [diff2html](https://www.npmjs.com/package/diff2html) – Gagan Jan 20 '21 at 08:59
  • [diff2html](https://github.com/rtfpessoa/diff2html) is hosted now on github. – Gagan Jun 12 '21 at 12:31
8

how about Text-Diff-HTML, difflib.HtmlDiff, CSDiff?

ax.
  • 58,560
  • 8
  • 81
  • 72
  • 3
    These 3 tools appear to generate diff files. I think the original question was asking for prettifying already generated diffs. – jarjar Jan 17 '12 at 21:53
  • For an online version, check out http://changedetection.com/ and http://imnosy.com/ – onassar Feb 23 '13 at 06:01
6

Have you tried http://prettydiff.com/ as it ignores differences in white space and comments.

[Disclaimer: this is my site]

theChrisKent
  • 15,029
  • 3
  • 61
  • 62
austin cheney
  • 63
  • 1
  • 2
5

The best I've found that produces nice side-by-side diffs is this script:

http://tools.ietf.org/tools/rfcdiff/

Although it's designed to be used on RFCs it works with any text file.

This project also has nice output, but I'm not sure if it can be used without subversion: http://code.google.com/p/coderev/

Andy Longwill
  • 624
  • 9
  • 25
5

There's also 2html in Vim, which works very well, and it's built-in: it takes a file that Vim knows how to highlight its syntax, and creates an HTML with the correct formatting. To use it, just open the wanted file with Vim, and source the 2html script. It will open the converted file in a new buffer, which can be saved. Here:

vim example.diff

and then in Vim,

:so /usr/share/vim/vim72/syntax/2html.vim
:wqa
Daniel Hershcovich
  • 3,751
  • 2
  • 30
  • 35
3

I found coderev, demo looks nice

ren
  • 3,843
  • 9
  • 50
  • 95
3

I use htmlize in Emacs. Doesn't come with Emacs, and assumes you're using Emacs. Relies on the syntax highlighting of Emacs's Diff mode. Only good for doing one file at a time. Does the right thing for me.

ashawley
  • 4,195
  • 1
  • 27
  • 40
  • 1
    Once you installed it with M-x package-install htmlize (within emacs), you can simply call emacs as `emacs --file fms-src-77-to-78.diff -f htmlize-file -f kill-emacs` (though this still requires you to hit enter once) – Arne Babenhauserheide Sep 23 '16 at 15:20