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.
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
gdScript: A customgd(git diff) shell script, powered byfzf, 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
deltadirectly into standard Git commands such asgit show,git diff,git add -p, andgit blame. ripgrepSynergy: A bonus tip demonstrates howripgrep's output can be piped intodeltato highlight search matches, adding another layer of utility.- Installation & Configuration: Users will need to install
delta(oftengit-deltavia package managers) andfzf. A key shell configuration fordeltaisexport 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.