Git Delta is a command line utility that beautifies git diffs in the terminal. But did you know that it can do the same in Magit too?
Delta is a highly configurable
I am not kidding. Check out the output of
command line utility that makes the git diffs look better, while also
Difftastic is another popular diff tool which compares files based on
their syntax. I like reviewing git diffs from within Emacs
(Magit). But difftastic does not support Magit.
the code in the diffs.
When I first heard of “syntax highlighted diffs”, I wasn’t sure what that meant. If you are in the same boat, here’s a screenshot that shows that.
But I do most of my git operations including viewing of diffs from within Emacs, using Magit.
.. and thankfully delta works with Magit!
Below screenshot shows how the same diff looks like in Magit.
magit-delta Emacs package makes this possible, which is also
developed by the
delta author Dan Davison.
- If the line numbers are enabled in
delta, they mess up the interactive expanding and collapsing of diffs in Magit. See Magit Delta Issue # 13 for more details.
Now, I am alright with not seeing the line numbers in Magit. But I
really liked to see the line numbers in the side-by-side view in the
terminal. Luckily, if disabled the
line-numbers feature but enabled
side-by-side view, I got what I wanted!
- Line numbers are disabled in Magit and expanding/collapsing of
diffs works correctly. I am also really glad that I don’t see the
side-by-side view in Magit diffs even when I enable that feature in
delta, because I like to have my Emacs buffers only about 90 characters wide.
- Line numbers and side-by-side view are enabled in the terminal.
I’ll end this post with pointers to installing
magit-delta and how to configure them.
You can install
delta (it’s called
git-delta in some package
managers) using one of the methods listed in its manual, or you can
download → extract its statically compiled binary for your OS from its
GitHub Releases page.
Once you put this snippet in your Emacs config and evaluate it, it
will install this package and enable the
magit-delta-mode in the
(use-package magit-delta :ensure t :hook (magit-mode . magit-delta-mode))
Here’s a snippet for
delta configuration from my
mostly the same as the one in delta’s the Getting Started guide. The
main difference in my workaround for the
[core] pager = delta [interactive] diffFilter = delta --color-only [add.interactive] useBuiltin = false # required for git 2.37.0 [diff] colorMoved = default [delta] # https://github.com/dandavison/magit-delta/issues/13 # line-numbers = true # Don't do this.. messes up diffs in magit # side-by-side = true # Display a side-by-side diff view instead of the traditional view # navigate = true # Activate diff navigation: use n to jump forwards and N to jump backwards relative-paths = true # Output all file paths relative to the current directory file-style = yellow hunk-header-style = line-number syntax