Update 2017 (2 years later)
Jaybeecave mentions in the comments the tool diff2html.xyz, a diff parser and pretty html generator.
The git diff format is inspired by the diff -p unix command.
(with -p being for --show-c-function: Show which C function each change is in.)
As I explain in "Where does the excerpt in the git diff hunk header come from?", that feature ("Show which C function") has evolved to take into account other language.
This is similar to what you see in the patch field of the JSON answer when you compare two commits with the GitHub API.
That feature was introduced in December 2012
Simply use the same resource URL and send either
application/vnd.github.difforapplication/vnd.github.patchin theAcceptheader:
curl -H "Accept: application/vnd.github.diff" https://api.github.com/repos/pengwynn/dotfiles/commits/aee60a4cd56fb4c6a50e60f17096fc40c0d4d72c
Result:
diff --git a/tmux/tmux.conf.symlink b/tmux/tmux.conf.symlink
index 1f599cb..abaf625 100755
--- a/tmux/tmux.conf.symlink
+++ b/tmux/tmux.conf.symlink
@@ -111,6 +111,7 @@ set-option -g base-index 1
## enable mouse
set-option -g mouse-select-pane on
set-option -g mouse-select-window on
+set-option -g mouse-resize-pane on
set-window-option -g mode-keys vi
set-window-option -g mode-mouse on
# set-window-option -g monitor-activity off
The format follows the classic diff unified format (also detailed here).
You can see an example in cubicdaiya/node-dtl (an dtl(diff template library) binding for node.js)
» npm install git-diff
Videos
» npm install parse-git-diff
» npm install gitdiff-parser
For those looking for more clear answer:
const nodegit = require('nodegit');
const repo = await nodegit.Repository.open(repoDirectory);
const from = await repo.getCommit(fromCommitSHA);
const fromTree = await from.getTree();
const to = await repo.getCommit(toCommitSHA);
const toTree = await to.getTree();
const diff = await toTree.diff(fromTree);
const patches = await diff.patches();
for (const patch of patches) {
console.log(patch.newFile().path());
}
Every patch represents a modified file and is an instance of ConvenientPatch. It has two methods oldFile() and newFile() which return an instance of DiffFile representing the file before and after modification.
NodeGit API docs:
- ConvenientPatch: https://www.nodegit.org/api/convenient_patch/
- DiffFile: https://www.nodegit.org/api/#DiffFile
- All API docs: https://www.nodegit.org/api/
I need this too, but it seems is not supported by nodegit yet.
Having a look at https://github.com/nodegit/nodegit/blob/master/lib/commit.js#L196 I see the diff is calculated by comparing the commit tree and the parent tree:
return thisTree.diffWithOptions(parentTree, options)
So, I assume this could be achieved by implementing a variation of commit#getDiff that receives another commit's OID and calls tree1 = this.getTree() and tree2 = getTheOtherCommit(OID).getTree() and then invoke tree1.diffWithOptions(tree2, options).
Of course the getTheOtherCommit is pseudocode but it's just to picture the idea.
As soon as I can I will try to implement it and post the progress here.