在javascript中以html的形式在客户端显示Git差异

简而言之,我基本上是在寻找有关以下信息:

>一种将Git的diff格式(它为您提供github api)转换为某种html格式的方法,例如在实际的github网站上.如果没有那样的话
>我想了解git的diff文件格式的一些信息,所以我可以自己编写.

解决方法:

2017年更新(2年后)

Jaybeecave提到了in the comments工具diff2html.xyz,差异分析器和漂亮的html生成器.

git diff格式受diff -p unix命令启发.
(-p代表–show-c-function:显示每个更改位于哪个C函数中.)

正如我在“ Where does the excerpt in the git diff hunk header come from?”中所解释的那样,该功能(“显示哪个C函数”)已经发展为考虑其他语言.

这类似于您在JSON答案when you compare two commits with the GitHub API的补丁字段中看到的内容.
该功能是introduced in December 2012

Simply use the same resource URL and send either application/vnd.github.diff or application/vnd.github.patch in the Accept header:

curl -H "Accept: application/vnd.github.diff" https://api.github.com/repos/pengwynn/dotfiles/commits/aee60a4cd56fb4c6a50e60f17096fc40c0d4d72c

结果:

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

格式遵循经典的diff unified format(也包括detailed here).
您可以在cubicdaiya/node-dtl中看到一个示例(用于node.js的dtl(差异模板库)绑定)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐