Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

for my upcoming Bachelor thesis, I am required to print out the git-diff output for the appendix of the paper. I really like the output of git diff --color-words, but I have absolutely no idea how to bring this - colored 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 seem not able to make a pretty print out of the single file's diffs.

Well, I am pretty sure that I cannot be the only one with this problem, and I found some suggested ansi2html solutions, but they to 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.

Thanks for your help!

like image 289
Timo Josten Avatar asked Sep 28 '12 16:09

Timo Josten


People also ask

How do I see git diff?

You can run the below commands to compare the changes for specific file: git diff HEAD <file_name> git diff <file_name>

What is the output of git diff?

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.

Why is git diff not showing?

In answer to the original question, git diff isn't showing anything because you have a brand new directory, with a newly added file, but there are zero changes in the file for git diff to show. git status is showing that you added a new file, but git diff is for showing changes within files.


2 Answers

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.

like image 173
onionjake Avatar answered Sep 22 '22 15:09

onionjake


I just tried an npm package hosted on Github: pretty-diff

You install it via npm and run it as you would with git-diff, for example:

pretty-diff HEAD^ 

A new browser window opens and you can save it as html. I've tried to open it again in a different browser and colors are still showing. You can also use your github account to create gists and share them.

like image 28
ithil Avatar answered Sep 23 '22 15:09

ithil