【问题标题】:Display Git diff on client side in javascript as html [closed]在javascript中将客户端的Git diff显示为html [关闭]
【发布时间】:2015-01-24 22:16:25
【问题描述】:

所以,简而言之,我基本上是在寻找一些信息:

  1. 一种将 Git 的 diff 格式(它为您提供 github api)转换为某种 html 格式的方法,例如在实际的 github 网站上。如果没有这样的事情,
  2. 我想知道一些关于git的diff文件格式的信息,所以我可以自己写。

【问题讨论】:

  • 就没有人有想法吗?
  • 正如Jaybeecave 下面提到的(我已经编辑了答案),你可以考虑diff2html.xyz
  • 我不明白为什么有些人喜欢使用flag 来关闭问题,规则是严格的,但人们是灵活的。应该鼓励好的事情而不是关闭。

标签: javascript git diff patch


【解决方案1】:

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 APIpatch 字段中看到的内容。
该功能是introduced in December 2012

只需使用相同的资源 URL 并在 Accept 标头中发送 application/vnd.github.diffapplication/vnd.github.patch

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(diff 模板库)绑定)

【讨论】:

  • 是的,但是格式是什么,有没有办法在客户端JS中将其转换为HTML?
  • @ChristopherDumas 不确定 html 部分,但我已在(现已编辑的)答案中添加了格式。
  • diff2html.xyz 是你想要的
  • @Jaybeecave 不错!我已将您的评论包含在答案中以提高知名度。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
  • 1970-01-01
  • 2011-11-24
  • 2011-04-16
  • 2016-12-10
  • 1970-01-01
相关资源
最近更新 更多