gitprintingdiffgit-diff

How do I prettily print out a git-diff output?


I am required to print out the git diff output for the appendix of a thesis paper. I really like the output of git diff --color-words, but I have absolutely no idea how to bring this formatting, with the colors and with line numbers included, to a piece of paper on my Mac. I know there are tools like SourceTree, but even with those I cannot seem to make a pretty print out of a single file's diffs.

I found some suggested ansi2html solutions, but they do not seem to work with my version of git (1.7.10.2). I also thought about simply printing the Github commit page (which is really pretty and kind of looks like what I need), but the browser will automatically remove all coloring and formatting when I am trying to print it.


Solution

  • Use aha. You can install it in ubuntu with sudo apt-get install aha. Also see https://github.com/theZiz/aha.

    $ git diff --color-words | aha > index.html
    $ firefox index.html
    

    Firefox should then be able to print it in color. Check out aha --help for some other cool options.