I enjoy using git diff --color-words
to clearly see the words that have changed in a file:
However I want to share that diff with someone without git or a colour terminal for that matter. So does anyone know of a tool or trick that can convert colour escaped terminal output into HTML?
In the diff view there is a file tree showing all of the changes for that pull request. The colour of a particular file indicates the file change type: Green - ADDED (a new file was added) Blue - MODIFIED (an existing file was modified) Brown - COPIED (an existing file was copied to create a new file)
git diff --color-words git diff also has a special mode for highlighting changes with much better granularity: ‐‐color-words . This mode tokenizes added and removed lines by whitespace and then diffs those. Now the output displays only the color-coded words that have changed.
Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.
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/
.
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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With