HN
Today

Improved Git Diffs with Delta, Fzf and a Little Shell Scripting

This post dives into supercharging Git diffs with delta and fzf, coupled with custom shell scripting for a highly visual and interactive experience. It addresses the common developer pain point of deciphering code changes, offering practical, immediately implementable configurations. The appeal on Hacker News lies in its clear, actionable advice for optimizing a fundamental developer workflow.

11
Score
2
Comments
#8
Highest Rank
7h
on Front Page
First Seen
Mar 28, 2:00 PM
Last Seen
Mar 28, 8:00 PM
Rank Over Time
1081113151716

The Lowdown

Nick Janetakis outlines a powerful setup to revolutionize Git diff readability and workflow using the delta diff viewer, fzf for fuzzy finding, and custom shell scripts. The author, who uses this system daily for PR reviews, shares his dotfiles and explains how developers can integrate these tools to make spotting code differences significantly more efficient and visually appealing.

  • Enhanced Diffs with Delta: The core of the setup involves delta, a highly recommended CLI tool that provides improved code difference visualization with character and word-level highlighting and dual-tone colors.
  • Interactive gd Script: A custom gd (git diff) shell script, powered by fzf, creates an interactive Text User Interface (TUI) allowing users to quickly jump between files within a diff. This is particularly useful for comparing branches (e.g., gd main..) and PR reviews.
  • Seamless Git Integration: The article provides configuration details to integrate delta directly into standard Git commands such as git show, git diff, git add -p, and git blame.
  • ripgrep Synergy: A bonus tip demonstrates how ripgrep's output can be piped into delta to highlight search matches, adding another layer of utility.
  • Installation & Configuration: Users will need to install delta (often git-delta via package managers) and fzf. A key shell configuration for delta is export DELTA_FEATURES="diff-so-fancy" to enable the most visually pleasing diff style.

This comprehensive guide transforms the often-tedious task of reviewing code changes into a streamlined, visually intuitive process, leveraging robust open-source tools.