<分区>
所以,简而言之,我基本上是在寻找以下信息:
- 一种将 Git 的差异格式(它为您提供 github api)转换为某种 html 格式的方法,就像在实际的 github 网站上一样。如果没有那样的话,
- 我想了解一些关于 git 的 diff 文件格式的信息,所以我可以自己编写。
标签 javascript git diff patch
<分区>
所以,简而言之,我基本上是在寻找以下信息:
最佳答案
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 的 patch
字段中看到的内容.
该功能是 introduced in December 2012
Simply use the same resource URL and send either
application/vnd.github.diff
orapplication/vnd.github.patch
in theAccept
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/