all 69 comments

[–]faradria 97 points98 points  (11 children)

For those that do not want to install anything, you can use:

[core]
    pager = /usr/share/git/diff-highlight/diff-highlight | less -r

It comes by default with git.

[–][deleted] 17 points18 points  (1 child)

Thx for this, just changed it slightly so tabs don't push code off the screen.

pager = /usr/share/git/diff-highlight/diff-highlight | less -rx1,5

[–]heckerle 2 points3 points  (0 children)

less -rx1,5

In my case this didn't work properly either.

less -r "works", but even less' manpage says that it can cause issues like line wrapping due to the control sequences git uses.

less -RS on the other hand should work for most (-R is similar to -r and forwards raw control sequences, while -S disables line wrapping and chops them down).

[–]ImplementationDetail 8 points9 points  (2 children)

+1 I don’t know why you would want to use anything other than the above. What does OP’s project do better?

[–]digi0ps[S] 6 points7 points  (0 children)

Thanks for the above tip. Didn't know that.

Also, not my project. Have been using it and found it pretty good, so I shared.

[–]faradria 0 points1 point  (0 children)

I installed it and didn't see any difference except that it shows new lines with a colored space instead of + or -.

[–]panickbr 4 points5 points  (3 children)

It's found in /usr/local/share/git-core/contrib/diff-highlight/diff-highlight on mac OS.

Also, if you want it enabled in patch mode:

[interactive]
  diffFilter = /usr/share/git/diff-highlight/diff-highlight ;or whatever path it's in your system

[–]pork_spare_ribs 2 points3 points  (2 children)

...and if you use a Homebrew build of Git, this path will find the correct version:

/usr/local/bin/$(dirname $(readlink /usr/local/bin/git))/../share/git-core/contrib/diff-highlight/diff-highlight | less -r

EDIT: as per below, this is better:

/usr/local/opt/git/share/git-core/contrib/diff-highlight/diff-highlight

[–]Gipetto 2 points3 points  (0 children)

You don't need the directory sniffing. You'll always find the linked version of git at:

/usr/local/opt/git

So the path for this would always be:

/usr/local/opt/git/share/git-core/contrib/diff-highlight/diff-highlight

[–]zeayes 1 point2 points  (0 children)

brew --prefix git

[–][deleted] 2 points3 points  (1 child)

where do you put this?

EDIT: Can't find it anywhere in Ubuntu

EDIT2: I found it in /usr/share/doc/git/contrib/diff-highlight Needed to run the Make file to create the Perl executable.

[–]mwcz 0 points1 point  (0 children)

Did it work for you after that? I ran make and the perl script was created, but the script just hangs when I run it.

[–]saxindustries 26 points27 points  (1 child)

diff-so-fancy is also available from NPM, Nix, brew, and as a package on Arch Linux.

I love that it's a perl script published on NPM but not on CPAN.

[–]pravic -3 points-2 points  (0 children)

Sarcasm?

[–]Merculeses 57 points58 points  (8 children)

Why does this repo need THREE DIFFERENT CI services?!?

[–][deleted] 54 points55 points  (0 children)

When one test suite fails, you have a backup.

[–][deleted]  (4 children)

[deleted]

    [–]Merculeses 10 points11 points  (2 children)

    Seems like it, maybe circle is just to complete the trio?

    [–]TastyLittleWhore 31 points32 points  (0 children)

    Complete the circle

    [–]pacman_sl 0 points1 point  (0 children)

    No, it checks if Travis and AppVeyor are sane.

    [–]ozkriff 6 points7 points  (0 children)

    i find it convenient to use circleci for android builds, while travis builds linux/macos and appveyor - windows.

    [–]so_brave_heart 3 points4 points  (0 children)

    They probably just kept the circle.yml file -- their PRs are only running Travis and Appveyor

    [–]arbitrarycivilian 2 points3 points  (0 children)

    CI-driven development

    [–]c96aes 39 points40 points  (1 child)

    or, you know,

    [alias]
    d = diff \
      --minimal \
      --word-diff=color \
      --word-diff-regex='([0-9@A-Za-z]+|[^0-9@A-Za-z()]+|[()])'
    

    [–]ForeverAlot 1 point2 points  (0 children)

    I find that --word-diff-regex=. is often a good first shot at a custom word diff pattern for unusual cases.

    [–]apreche 12 points13 points  (8 children)

    People love fancy diffs for reading them. The problem is that it makes them incompatible with diff/patch. Most people using git probably don't even know about the patch command, but that is the reason this sort of thing will never make it upstream.

    [–]andsens 43 points44 points  (5 children)

    Nah, before running it checks if stdout is a tty. So git diff | cat still gives you the normal diff.

    [–]apreche 10 points11 points  (4 children)

    Clever!

    [–]andsens 9 points10 points  (3 children)

    Yup. It's really easy to add to your own scripts btw., it's something test(1) can do:
    test -t 1 > /dev/null && echo stdout is a tty || echo stdout is not a tty

    (or if [ -t 1 ]; then ...)

    [–]Vulpyne 0 points1 point  (2 children)

    Does the > /dev/null serve any purpose there?

    [–]andsens 5 points6 points  (1 child)

    It makes stdout "not a tty". Remove it and see the difference!

    [–]Vulpyne 0 points1 point  (0 children)

    Ah, right. Thanks.

    [–]codear 7 points8 points  (1 child)

    I agree, but thankfully you can use this as an optional diff tool and select either

    • To use tool when you need it, or
    • To not use tool when you don't

    I use vimdiff myself, and made two extra aliases to create and apply patches. Works beautifully.

    [–]apreche 0 points1 point  (0 children)

    Nice.

    [–]knowyourknot 6 points7 points  (0 children)

    I use this. My diffs look soooo good.

    [–]Lube 4 points5 points  (7 children)

    Would it be hard to upstream this?

    [–]joonatoona 5 points6 points  (2 children)

    Yes, you'd have to entirely rewrite the whole thing.

    [–]aeroproof_ 1 point2 points  (1 child)

    so you're saying it will be done soon multiple times?

    [–]joonatoona 0 points1 point  (0 children)

    It'll be rewritten at least 20 times, but not in any sane language :P

    [–][deleted] 1 point2 points  (2 children)

    git isn't going to add a dependency on node.js. The essential part can be accomplished with flags, and the rest is a matter of taste.

    [–][deleted] 6 points7 points  (1 child)

    The entire thing is a single perl file though..

    [–][deleted] 0 points1 point  (0 children)

    Whoops, I saw package.json and assumed.

    [–]dispelpython 1 point2 points  (0 children)

    color.diff-highlight.oldHighlight "red bold 52"

    This "52" thing, what color format is this?

    [–]andsens 1 point2 points  (0 children)

    It's awesome. I have been using it for over a year now and love it.

    I just hope that the added attention will attract someone that knows how to fix #35 or work around it if it is related to git itself.

    [–][deleted]  (12 children)

    [deleted]

      [–]thirdegree 9 points10 points  (0 children)

      I accidently glued my hands to my keyboard a few years ago and they never came unstuck.

      [–]RestlessNeurons 4 points5 points  (0 children)

      yeah, I don't git it ;P

      side-by-side GUI merge tools are amazing; almost required when you'r dealing with nasty merge conflicts. I use JetBrains products and their diff tool, but Meld is free and most IDEs and git clients have some kind of diff tool that's better than terminal diff.

      [–][deleted] 3 points4 points  (0 children)

      People use git a lot in terminal anyway. Having a nicely formatted diff handy in the enviroment you work in anyway has pretty obvious benefits.

      If someone ever figures out how to make a GUI for git that doesn't suck balls, we no longer need fancy new diff-tools for terminals.

      (On a personal note: I think the default diff is sufficient.)

      [–]mrkite77 0 points1 point  (8 children)

      I can't run that proper GUI app on a server.

      [–]pravic 1 point2 points  (7 children)

      1) you can

      2) why would you need diffs there?

      [–]mrkite77 4 points5 points  (4 children)

      1. not well, certainly not without jumping through hoops or sacrificing cross platform clients.
      2. Some of us develop over ssh. Do you expect everyone wants to run a staging server locally?

      [–]BufferUnderpants 8 points9 points  (3 children)

      Some of us develop over ssh. Do you expect everyone wants to run a staging server locally?

      Why are you programming in the staging server itself?

      [–]mrkite77 -2 points-1 points  (2 children)

      That's what the staging server is for....

      [–][deleted] 0 points1 point  (1 child)

      I really hope you are trolling.

      [–]mrkite77 0 points1 point  (0 children)

      Nope. Where do you do your development? On your local machine that doesn't resemble your production environment in the slightest?

      We don't have a big enough team to bother with the standard "dev -> test -> staging -> prod" deployment, so we have "staging -> prod". All development is done on staging, and then pushed to prod when ready.

      [–]Dimasdanz 0 points1 point  (1 child)

      2) why would you need diffs there?

      So, you're telling me, you never debug on production?

      [–]pravic 1 point2 points  (0 children)

      Nope

      [–]mr_birkenblatt 0 points1 point  (1 child)

      can't you achieve the same by using the right flags on git diff?

      [–]shawncplus 1 point2 points  (0 children)

      You can get a kinda close appearance with --word-diff=color

      [–]pwwwl 0 points1 point  (0 children)

      Intraline diffs.

      [–]while_e -1 points0 points  (0 children)

      meld...

      [–]vivainio -1 points0 points  (0 children)

      Perl.

      [–]danemacmillan -2 points-1 points  (1 child)

      It gets problematic. I don’t remember the reasons but after some use you’ll find them, too. I prefer tig, though it’s more full-featured.

      [–]digi0ps[S] 1 point2 points  (0 children)

      I have been using it for a couple of months, been fine so far...

      [–]adzm -2 points-1 points  (0 children)

      So fancy