From 88e675b9a33e5ab3c1569c291f1ca557755d05f0 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 15 Dec 2024 18:31:25 -0600 Subject: [PATCH] Add Better Diffs With Delta as a Git TIL --- README.md | 3 ++- git/better-diffs-with-delta.md | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 git/better-diffs-with-delta.md diff --git a/README.md b/README.md index 71723aa..08c2e97 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1538 TILs and counting..._ +_1539 TILs and counting..._ --- @@ -283,6 +283,7 @@ _1538 TILs and counting..._ - [Add Only Tracked Files From A Directory](git/add-only-tracked-files-from-a-directory.md) - [Amend Author Of Previous Commit](git/amend-author-of-previous-commit.md) - [Auto-Squash Those Fixup Commits](git/auto-squash-those-fixup-commits.md) +- [Better Diffs With Delta](git/better-diffs-with-delta.md) - [Caching Credentials](git/caching-credentials.md) - [Change The Start Point Of A Branch](git/change-the-start-point-of-a-branch.md) - [Check How A File Is Being Ignored](git/check-how-a-file-is-being-ignored.md) diff --git a/git/better-diffs-with-delta.md b/git/better-diffs-with-delta.md new file mode 100644 index 0000000..87b385f --- /dev/null +++ b/git/better-diffs-with-delta.md @@ -0,0 +1,43 @@ +# Better Diffs With Delta + +A `git diff` from the command line is relatively bare bones. It shows you +removed lines and added lines that make up a changeset with the former text in +red and the later text in green. All other contextual text is in white. I've +found this to be good enough for most of the life of my git usage. I've been +missing out though. + +By using [`delta`](https://github.com/dandavison/delta) as the pager and diff +filter for `git`, I get a bunch of nice visual improvements. + +- Removals and additions are red and green shaded backgrounds +- Syntax highlighting for most languages +- Highlight specific part of a line that has changed +- Visual spacing and layout is clearer + +To get all of this, all I had to do was install `delta`: + +```bash +$ brew install delta +``` + +And then add `delta` as both the _core_ pager and `diffFilter` in my global git +config file: + +``` +[core] + pager = delta +[interactive] + singleKey = true # unrelated, but nice to have + diffFilter = delta --color-only +``` + +It's also recommended that you use `zdiff3` for your merge conflict style, +which I already had: + +``` +[merge] + conflictstyle = zdiff3 +``` + +Once you have ths all configred, try a `git diff` or `git add --patch` and see +how much more visual info you get.