Developer builds tool to make git diff understand JSON and YAML structure
A developer created a custom tool to give git diff semantic awareness of structured data formats like JSON and YAML, after a Kubernetes manifest formatter reordered keys and produced noisy, misleading diffs. Git offers two extension points for this: an external diff driver that fully replaces the diff output, and a textconv filter that normalises file content before comparison. A key discovery was that these two hooks behave differently across git commands — the external driver only activates for git diff, while history commands like git log -p and git show fall back to textconv. Several edge cases required careful handling, including invalid mid-edit files that could abort an entire diff run, temp files without reliable extensions, and encoding issues that could silently erase content. The author recommends starting with a simple shell shim for existing tools, but notes a dedicated subcommand offers better error messaging, cross-platform support, and more reliable file-type detection.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in