Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

diff2html-cli turns Git or unified diff output into a readable HTML review. Install it with npm, choose whether the input comes from a Git command, a saved diff file, or standard input, then preview the result, save it as HTML, or send output to stdout. Use -s side for a side-by-side layout or -s line for a line-by-line view.

Install diff2html-cli

The npm package is installed globally with:

npm install -g diff2html-cli

The package metadata lists version 5.2.15. The project describes the utility as a terminal tool for generating HTML diffs from unified and Git diff output. See the diff2html-cli npm package and the official project repository.

Generate an HTML diff from Git

Use -i command to have the CLI run a Git diff command. Put the CLI options first, then --, then the arguments passed to Git:

diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1

This documented example previews the diff for HEAD~1 in a browser, using a line-by-line layout and word-level highlighting. The -- separator matters: it marks where diff2html-cli options end and the Git arguments begin.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose an input source

Run a Git command

Use -i command when you want diff2html-cli to obtain the diff from Git. Git-specific options go after --, as in the preceding example.

Read a saved diff file

Use -i file and give the diff file path after the separator:

diff2html -i file -- my-file-diff.diff

Read diff text from stdin

Pipe unified diff output into the CLI with -i stdin:

diff -u file1.txt file2.txt | diff2html -i stdin

Choose the layout and diff detail

The -s option selects the comparison layout: line displays changes line by line, while side places the compared versions side by side. The related Diff2Html library calls these formats “line-by-line” and “side-by-side.” The --diffStyle option controls word- or character-level highlighting, and --matching can be used for line or word matching. Consult the CLI README for the available options and values.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Preview, save, or emit the result

Preview in a browser

Set -o preview to open a browser preview, as in the Git example above.

Save HTML to a file

Use -F or --file to write the generated HTML to a named file:

diff2html -F my-pretty-diff.html -- -M HEAD~1

Write output to stdout

Set the output format and choose -o stdout to write to standard output. For example, this command emits JSON rather than HTML:

diff2html -f json -o stdout -- -M HEAD~1

Choose the format and output destination that match the next step in your workflow: a browser review, an HTML artifact, or output consumed by another command.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Review aids and large-diff controls

The CLI offers options for file summaries, toggling file contents, synchronized horizontal scrolling, syntax highlighting, and automatic, light, or dark color schemes. It also exposes limits for changed lines, line length, comparisons, and highlighting. Those controls can keep very large diffs or unusually long lines from being rendered without limit; they are configuration controls, not published performance guarantees. Option names and supported values are documented in the project README.

Customize the HTML wrapper

Use --htmlWrapperTemplate to supply a custom HTML shell. The template needs the documented Diff2Html CSS and UI placeholders in its <head>, and a <div id="diff"> in its <body> containing <!--diff2html-diff-->. The project’s sample wrapper initializes Diff2HtmlUI after DOMContentLoaded; it can also enable file-list toggling, synchronized scrolling, and code highlighting. See the custom wrapper documentation and sample before adapting the template.

Understand exit statuses

Exit status Documented meaning
0 Success
1 Generic error
3 Input diff is empty
4 HTML wrapper template path is invalid

If a Git-based command fails unexpectedly, first check that the Git arguments follow --. For an empty-diff result, verify that the input source produced diff text.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.