javascript - 在客户端以 html 的形式在 javascript 中显示 Git diff

标签 javascript git diff patch

<分区>

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

  1. 一种将 Git 的差异格式(它为您提供 github api)转换为某种 html 格式的方法,就像在实际的 github 网站上一样。如果没有那样的话,
  2. 我想了解一些关于 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 APIpatch 字段中看到的内容.
该功能是 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(diff 模板库)绑定(bind))

关于javascript - 在客户端以 html 的形式在 javascript 中显示 Git diff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28130861/

相关文章:

javascript - Angular 4 : Can't bind to 'ngModel'

linux - 奇怪的差异行为

intellij-idea - IntelliJ 按文件路径重新排序更改选项卡

javascript - Jsp 属性按条件禁用

javascript - 登录失败的客户端通知

javascript - 如何将两个 editable-select 、 e-ng-options 绑定(bind)在一起?

git - 如何为 trac 存储库集成创建 git post-commit Hook

windows - 在 Windows 上的 git bash 中启用自动完成?

Git for Windows 停止工作 - VS Team Services

git - Beyond Compare git difftool -d 立即关闭,无需等待用户