41 comments

[ 2.5 ms ] story [ 78.1 ms ] thread
Delta[0] applies syntax highlighting to the code sections of git and diff output, and uses background colors (instead of +/-) to indicate added / removed content. It's written in Rust, and uses the syntect[1] highlighting library. That's the same library that bat[2] uses, so delta supports all the same color themes, and any bat configuration that you already have in place (environment variables, custom themes/language support) is automatically honored by delta. Delta also infers and highlights substrings that differ between lines (similar to Github, Gitlab and other diff viewers) and optionally cleans up the raw diff output slightly to make it more human readable.

[0] https://github.com/dandavison/delta

[1] https://github.com/trishume/syntect

[2] http://github.com/sharkdp/bat/

Does it work properly with `git add -p`? That's a longstanding issue of diff-so-fancy: https://github.com/so-fancy/diff-so-fancy/issues/35
Yes it does. Thanks for asking, I hadn't tested this out. The key is the `--color-only` argument, which guarantees that, other than ANSI color escape sequences, the original output from git is unchanged:

  [interactive]
      diffFilter = delta --color-only
Looks like it works 'properly' in the sense that it does all that it can (colouring, incl. syntax highlighting, which d-s-f never does) without making the result wonky.

The core issue is the same for delta as it is for d-s-f (or any other interactive pager) - there must be a 1:1 correspondence between lines out from git, and lines back into it.

So, delta can do the fancier colouring interactively, but it can't mess with the header either, for the same underlying reason. (And so 'solved' it with a `--color-only` flag.)

Just installed it, it looks great and is a big step up from diff-so-fancy. Thanks for making this!
This might be just me but looking at the screenshots, I clearly prefer the GitHub one as it shows the line numbers of every line in both before and after. Line numbers make jumping between the diff and the editor fast and efficient.
Thanks, that's definitely a feature that could be added. My original thought was that the line numbers in the after file are nearly always what one wants, since that's the version that your editor will most naturally be displaying. And I wanted to reduce visual clutter. Delta currently displays just the first line number of each diff hunk; not on every line. But that's also something that could be made configurable.

EDIT: In fact an issue was opened for this very recently: https://github.com/dandavison/delta/issues/130

Ideally, I think that a mouse click in an appropriate location in a terminal emulator window should open the user's editor on the correct line of the correct file.

Is there a way to see diff output side-by-side? I personally find that much easier to parse through with a widescreen monitor.
Hi, thanks, this is an interesting question and there have been requests for it. Two possibilities come to mind:

1. Delta constructs the side-by-side diff itself (a parsed internal representation of it), and then colorizes it.

2. Delta gains the ability to parse side-by-side diffs being emitted by another tool.

My currently feeling is that (1) is more attractive / easier.

#1 would be useful for sure.
As a suggestion, I'd have the configuration step in 'Configure git to use delta' not reference a theme that doesn't come with the initial install as you've done with 'base-16.ocean.dark'. I had to investigate why, and (admittedly happily) then found out about bat and installed that and changed it to 'zenburn'. But I suppose most users would like to see it work without having to do that.
I ran into the same issue, and chose the same theme I use with bat.
Thank you! Fixed that.
I don't know if this is better per-se but my diff-so-fancy config sat in [pager] rather than [core]. I verified that git-delta works as configured this way instead:

  [pager]
          diff = delta --dark --plus-color="#012800" --minus- color="#340001" --theme="zenburn"
The light theme looks beautiful, thanks!
Thanks. I like the light theme also. If anyone has suggestions of good {theme, background-highlight-colors} choices, especially for dark backgrounds, please open a PR/issue and we can add them to the README.
This is neat. In a similar fashion I'm a big fan of diff-highlight, [0] which post-processes the git diff and highlights with color the differing segments. It's super lightweight and part of the official git repo; I've saved it as a standalone #!/bin/perl in my $PATH and then included it in my .gitconfig:

  [pager]
   log = /Users/user/.bin/diff-highlight | less
   show = /Users/user/.bin/diff-highlight | less
   diff = /Users/user/.bin/diff-highlight | less
[0]: https://github.com/git/git/tree/master/contrib/diff-highligh...
I love that too! My config is almost the same, but I have "pager = ..." under "[core]"
Sort of related: as I never made diff-highlight work correctly on Windows, I wrote diffr[0] which goes a little bit behond what diff-highlight does.

[0]: https://github.com/mookid/diffr

icdiff is my current favorite.

This does look nice, though I'm a little confused by the choice to highlight the section below the function declaration change even though it doesnt appear to have a change.

Is it the hunk header you're referring to? That's something that git outputs, like this, before the diff hunk:

  @@ -62,17 +62,17 @@ class MyClass:
Delta makes that more prominent by surrounding it with a box (by default) and getting rid of the for-machines characters that git puts there. It doesn't apply background colors to it though: delta only applies background red and green shading to removed/added lines.

(I believe that one can customize the regular expressions that git uses to decide on the hunk header; they're sometimes appropriate and sometimes not, for the languages that I use.)

Can anybody suggest a --plus-color that looks nice on a solarized-dark blue terminal?
I settled on --plus-color="#157330" --minus-color="#731525".
I can't tell if --dark is changing anything. That seems to be the default on my dark terminal?
Yes, --dark is the default and it will choose a dark theme. To see a demo of other dark themes, you can do

  delta --list-themes --dark
and then delta --theme <chosen theme> to select it.
This is fantastic. Kudos!

A tip for people who (like me) don't like that Git pages by default: With Delta, you can disable this it by adding this to your environment:

  export BAT_PAGER=cat
(comment deleted)
I think there’s ‘tig’ as well. You can use it as ‘git diff | tig’
Anyone else getting this issue?

  ⟩ git diff
  error: Found argument 'Extended' which wasn't expected, or isn't valid in this context

  USAGE:
      delta --dark --minus-color <minus_color> --plus-color <plus_color> --theme <theme>

  For more information try --help

My ~/.gitconfig file has the copy pasted lines from the github example

  [core]
      pager = delta --dark --plus-color="#012800" --minus-color="#340001" --theme="Monokai Extended"

  [interactive]
      diffFilter = delta --color-only
Installed with homebrew on macos.
Thanks! I made a hasty edit to the README earlier. Try

  --theme='Monokai Extended'
It seems that in ~/.gitconfig, a theme name with spaces must be quoted with single quotes. At least, that is working on MacOS.
FYI that dark theme example has unreadable blue for me in looking at it with night shift on. I'd suggest swapping out for a better theme.
I agree. If anyone has nice combinations of delta background colors and syntax highlighting theme for dark backgrounds, please send them my way! (Here, or PR/issue).
Stuff like that makes my daily code reviews so so SO much better! I can't thank you enough!