Reputation: 666
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.
Upvotes: 24
Views: 31537
Reputation: 69
What I found pretty useful is to just pipe it into bat, a modern cat. If you want only a specific diff the command can be used as usual.
git diff | bat
You can also set up an alias in your shell profile to avoid typing it out every time.
Also delta is awesome.
Offical Description: A syntax-highlighting pager for git, diff, and grep output
Even if you not set it as default pager in your configuration you can pipe the git diff output into it.
git diff origin/main | delta --side-by-side
is what I use daily
Upvotes: 3
Reputation: 11
If anybody wanted to print the diff output in a GitHub comment with line highlights:
git diff > changes.txt
This will make a file changes.txt with all the needed diffs, but when you paste it in the comment, it will not have highlights. You need to start the comment with:
```diff
Leave a line and then print the contents of changes.txt
Upvotes: 0
Reputation: 19
Since you are using a Mac with the terminal application, it is as simple as cut and pasting from the terminal to another application.
Upvotes: 1
Reputation: 1768
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.
Upvotes: 11
Reputation: 4045
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.
Upvotes: 19