Git-diff to HTML

前端 未结 3 1575
耶瑟儿~
耶瑟儿~ 2021-02-09 23:06

I\'m looking for a way to produce HTML files from a git-diff output, preferably using python. I\'ve been looking at http://docs.python.org/library/difflib.html without being abl

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-09 23:28

    You could use the pygments commandline script to get a syntax highligthed HTML output.

    Installation:

    $ easy_install Pygments
    

    Example:

    $ git diff HEAD^1 > last.diff
    $ pygmentize -f html -O full,style=trac -l diff -o last.diff.html last.diff
    
    $ # mac only
    $ open last.diff.html
    

    Or shorter:

    $ git diff | pygmentize -f html -O full,style=emacs -l diff
    

    P.S. To see all available styles, try:

    $ pygmentize -L styles
    

    P.P.S. To make the pipeline complete, you can use this trick:

    $ git diff | pygmentize -f html -O full,style=emacs -l diff | browser
    

提交回复
热议问题