Coloured Git diff to HTML

前端 未结 7 567
盖世英雄少女心
盖世英雄少女心 2020-11-28 19:19

I enjoy using git diff --color-words to clearly see the words that have changed in a file:

\"Screen

相关标签:
7条回答
  • 2020-11-28 19:20

    If you want to see clean diffs with line similarity matching, better word comparison, syntax highlight and more check out diff2html which is very customizable git diff to HTML presenter.

    To use it on the command line you can check diff2html-cli which is a simple CLI written in Node.js.

    So you can share your diffs with colleagues it integrates with diffy.org.

    Check out a diff sample here.

    0 讨论(0)
  • 2020-11-28 19:21

    download diff2html, extract it and convert diff to html with this command:

    $ diff2html file1.txt file2.txt > diff-demo1.htm
    

    There is more ... take a look at this question.

    Or after gitting:

    git diff --color-words --no-index orig.txt /tmp/edited.txt > myfile
    

    download both ansifilter from this location. and use this command to convert myfile to html format

    ansifilter -i myfile -H -o myfile2.html
    

    so ... this is exactly what you want ;)

    0 讨论(0)
  • 2020-11-28 19:22

    You may want to checkout the github project rmed, which provides a command line tool, that generates static shareable html diffs using vimdiff.

    0 讨论(0)
  • 2020-11-28 19:25

    when I use git bash, if you use git show you only need to copy and paste what is shown in the console and it copies the colours correctly.

    0 讨论(0)
  • 2020-11-28 19:30

    Don't know any tool to do exactly what you want. But here's a piece of code I often use to output html formatted colored diff: simplediff

    It's available in PHP and Python. The output tags the differences using <del> and <ins> tags so you can easily color them using CSS.

    0 讨论(0)
  • 2020-11-28 19:34
    wget "http://www.pixelbeat.org/scripts/ansi2html.sh" -O /tmp/ansi2html.sh
    chmod +x /tmp/ansi2html.sh
    git diff --color-words --no-index orig.txt edited.txt | \
    /tmp/ansi2html.sh > 2beshared.html
    

    What I really needed was an ANSI to HTML converter. And I found a very decent one on http://www.pixelbeat.org/.

    NOTE: You might not see any coloration unless you include --color or --color-words, probably because piping causes git diff to exclude colors.

    NOTE 2: You may need to install gnu sed and awk, especially if you're on a Mac. Do so with brew install gnu-sed gawk. You may need to add them to your path manually, too, e.g. with ln -s /usr/local/Cellar/gnu-sed/4.2.2/bin/gsed /usr/local/bin/.

    0 讨论(0)
提交回复
热议问题