A personal pet peeve of mine when reading diffs, is when a file has some functions and you insert one and instead of looking like this:<p><pre><code> int someOldFunction()
{
// Function body
}
+
+int newFunction()
+{
+ // New function body
+}
</code></pre>
It looks like this:<p><pre><code> int someOldFunction()
{
// Function body
+}
+
+int newFunction()
+{
+ // New function body
}
</code></pre>
It's a small thing, but given that these diffs are equivalent, the one that balances the curly braces within added blocks should be favored. But diff utilities seem to get this pretty consistently wrong.
[I'm the author of diff-so-fancy, Steve helped with shipping it as a standalone script]<p>NPM?!? :)<p>A lot of people below are asking why a bash script (that depends on a perl script) is being recommended to install via NPM? The short reason is that NPM is the most straightforward way to get a script installed as a global binary in a cross-platform manner. This approach has worked quite well with `git-open`[0]. Asking all users to deal with the PATH is not my ideal.<p>In addition, I wanted a reasonable upgrade path, in case there are neccessary bugfixes. It's not a great experience if users identify bugs but the fix means they manually find it/download/PATH-ify each time. :/<p>That said, I'll add some Manual Install instructions to the readme so it's clear how to do this on your own. :)
( Edit: Here they are… <a href="https://github.com/stevemao/diff-so-fancy/blob/master/readme.md#manual-install" rel="nofollow">https://github.com/stevemao/diff-so-fancy/blob/master/readme...</a> )<p>[0] <a href="https://github.com/paulirish/git-open" rel="nofollow">https://github.com/paulirish/git-open</a>
Might be better to link to the source directly: <a href="https://github.com/paulirish/dotfiles/blob/master/bin/diff-so-fancy" rel="nofollow">https://github.com/paulirish/dotfiles/blob/master/bin/diff-s...</a>
If you don't want your diff so fancy (pun intended, and I'm sorry) but you still want the inline highlights, the script comes with git (<a href="https://github.com/git/git/tree/master/contrib/diff-highlight" rel="nofollow">https://github.com/git/git/tree/master/contrib/diff-highligh...</a>):<p><pre><code> ln -sf "$(brew --prefix)/share/git-core/contrib/diff-highlight/diff-highlight" ~/bin/diff-highlight
</code></pre>
and add to .gitconfig<p><pre><code> [pager]
log = diff-highlight | less
show = diff-highlight | less
diff = diff-highlight | less</code></pre>
I know he gave credit in the README, but why does this ~30 line shell script need its own repo? Seems more like a cheap grab for Github Stars rather than to provide actual value.<p>Edit: Even the screenshot is from Paul...
So, the whole npm thing seems weird to me, then it occurred to me that it could be for malicious purposes. Would it be possible to upload a separate package.json to npm that had eg a post-install script? I don't know much about how npm works from the package publication side of things, but I assumed it was similar to pypi where the code in the git repo doesn't have to be at all related to the code in the package
<p><pre><code> git diff --word-diff=color
</code></pre>
provides a really nice word diff with coloring similar to this project. Just setup an alias in your global gitconfig:<p><pre><code> [alias]
cdiff = diff --word-diff=color</code></pre>
what I'd like to see is that a/b in front of the filenames disappear. Getting rid of that would FINALLY allow me to double-click on the filename (which is configured to select the part between the spaces and copy it to the clipboard) and paste it instantly for the next command... or to be able to do git diff > foo.patch and on another system do patch < foo.patch without having to remember the correct -p value.
What happened to this line from the second file in the screenshot?<p><pre><code> - var optionsGlassPane = new WebInspector.GlassPane(document);
</code></pre>
An important part of viewing diffs for me is seeing what the old code was.
I handle this in a way that is more agnostic to the type of revision control, and fully flexible in coloring (using the most powerful scheme available).<p>For example, I shouldn't have to put up with basic colors if the terminal can do better.<p>Here is how it works; starting with:<p><pre><code> #!/bin/bash
if [ -r ".svn" ] ; then
exec svn diff ${1+"$@"} | my_colorize_diff
else
git diff ${1+"$@"} | my_colorize_diff
fi
</code></pre>
...where the "my_colorize_diff" script at the end of the pipe is as follows:<p><pre><code> #!/usr/bin/env perl
# by Kevin Grant (kmg@mac.com)
my $term_program = (exists $ENV{'TERM_PROGRAM'} && defined $ENV{'TERM_PROGRAM'}) ? $ENV{'TERM_PROGRAM'} : '';
my $term = (exists $ENV{'TERM'} && defined $ENV{'TERM'}) ? $ENV{'TERM'} : 'vt100';
my $is_xterm = ($term =~ /xterm/);
my $is_24bit = ($term_program =~ /MacTerm/);
print "\033#3BEGIN DIFF\n";
print "\033#4BEGIN DIFF\n\033#5";
while (<>) {
if (/^\+/ && !/^\+\+/) {
if ($is_24bit) {
print "\033[48:2:150:200:150m", "\033[2K", "\033[38:2::88:m", "\033[1m";
} elsif ($is_xterm) {
print "\033[48;5;149m", "\033[2K", "\033[38;5;235m", "\033[1m";
} else {
print "\033[42m", "\033[2K", "\033[30m", "\033[1m";
}
} elsif (/^\-/ && !/^\-\-/) {
if ($is_24bit) {
print "\033[48:2:244:150:150m", "\033[2K", "\033[38:2:144:0::m";
} elsif ($is_xterm) {
print "\033[48;5;52m", "\033[2K", "\033[38;5;124m";
} else {
print "\033[41m", "\033[2K", "\033[37m";
}
} else {
print "\033[3m";
}
chomp;
print;
print "\033[0m\n";
}
print "\033#3END DIFF\n";
print "\033#4END DIFF\n\033#5";</code></pre>
Nice improvement to diff but I think I'll still use `git difftool` with Diffmerge <a href="https://sourcegear.com/diffmerge/" rel="nofollow">https://sourcegear.com/diffmerge/</a>
I didn't quite like this, put it does reference diff-hightlight, which is part of git-contrib (so it may already be installed on your system, but just not in your $PATH!):<p><a href="https://github.com/git/git/tree/master/contrib/diff-highlight" rel="nofollow">https://github.com/git/git/tree/master/contrib/diff-highligh...</a><p>For example, here's a diff where it improved readability enormously:<p><a href="https://i.imgur.com/8iQNaeu.png" rel="nofollow">https://i.imgur.com/8iQNaeu.png</a>
I have an alias for the diff params bellow, which has basically the same visual result, without the need to install anything.<p><pre><code> $ git diff --color --color-words --abbrev</code></pre>
what are the advantages over colordiff[0]? (or a graphic differ like kdiff3[1])<p>[0] <a href="http://www.colordiff.org/" rel="nofollow">http://www.colordiff.org/</a>
[1] <a href="http://kdiff3.sourceforge.net/" rel="nofollow">http://kdiff3.sourceforge.net/</a>
We've grown and it's out of control. diff-so-fancy moved to an org!!!
<a href="https://github.com/so-fancy/diff-so-fancy" rel="nofollow">https://github.com/so-fancy/diff-so-fancy</a>
the netbeans.team.diff tool is similar (showing the specific words that changed), allows interactive editing, and does a good job even with large insertions and deletions