Harness the Combinatoric Power of Command-Line Tools and Utilities
Review Changes With Delta
Published May 2, 2024
Whether you’re looking at code or content, it’s helpful to see the changes you’ve made to a file, or to compare a file to a previous version. If you’re working within git
, you’re probably familiar with the git diff
command. The delta tool gives you more control over how you see what’s different, and you can use it as a standalone tool, or with git
.
Delta offers side-by-side diffs with line numbers, syntax highlighting, and built-in navigation support.
What You Need
To complete this tutorial, you need
- git installed on your local machine.
- Homebrew installed, which you can do by following the Install Homebrew tutorial.
Installing Delta
To install Delta, use your package manager to install the git-delta
package, or get a binary for your OS. If you go the manual route, make sure to place the executable on your system PATH
.
Once installed, you add configuration options to your global ~/.gitconfig
file:
[core]
pager = delta
[interactive]
diffFilter = delta --color-only
[delta]
navigate = true
light = true
side-by-side = true
[merge]
conflictstyle = diff3
[diff]
colorMoved = default
With this configuration, you will get side-by-side diffs, rather than the inline diffs, which is great for comparing lots of text changes. Change the light
option to false
if you use a dark-mode terminal.
To test it out, create a couple of Markdown files:
cat <<EOF > file1.md
This is the first file.
It has two lines.
EOF
cat <<EOF > file2.md
This is the second file.
It has three lines.
Isn't that great?
EOF
With the files created, run delta
to compare the files:
delta file1.md file2.md
You’ll see a side-by-side comparison, making it clear what’s changed:
Delta works well as a standalone diff tool, but it integrates with Git’s tooling as well.
When you use the git diff
command, it’ll invoke the delta
command instead of the default view.
Conclusion
Delta improves upon the traditional git diff
command. Whether you use it as a standalone tool or as part of your Git workflow, Delta offers a clearer, more informative view of file differences.