splitdiff
Visualize unified diffs side-by-side in terminal
SYNOPSIS
splitdiff
DESCRIPTION
splitdiff is a utility designed to process the output of a unified diff and break it down into separate diffs for each file that has been changed. This is exceptionally useful when reviewing large patch files or diffs generated from version control systems (like git diff or svn diff) that encompass modifications across numerous files. Rather than navigating one long, monolithic diff, splitdiff allows users to view or process changes on a file-by-file basis. It typically reads the unified diff from standard input and outputs individual diffs to standard output, often separated by clear headers for each file. This command significantly enhances the readability and manageability of complex code changes, making it simpler to analyze, apply, or reject specific file modifications independently. It's frequently employed as a pre-processor for other tools that are designed to handle single-file diffs.
CAVEATS
The standard GNU splitdiff utility is remarkably simple: it operates strictly on standard input and produces output on standard output without accepting any command-line options or arguments. It rigorously expects its input to be in the unified diff format; other diff formats (such as context diffs) will not be correctly processed and may lead to unexpected output. Its output is also in the unified diff format, but segmented by file.
While some third-party or custom splitdiff scripts might offer minimal options (e.g., for output directories), the canonical GNU version focuses solely on its core task of parsing and splitting unified diff output.
TYPICAL WORKFLOW
To view a large unified diff (e.g., from a patch file) one file at a time using a pager:
cat my_patch.diff | splitdiff | less
To split the output of a git diff into viewable chunks:
git diff | splitdiff | less
This allows you to navigate through the changes for each file individually, making large code reviews more manageable.
HISTORY
The splitdiff utility is often distributed as part of the GNU Diffutils package, which provides a comprehensive suite of tools for comparing files and directories. While its specific development history might be less documented than core utilities like diff or patch, its emergence stems from the widespread adoption of unified diffs in version control systems and modern software development practices. In workflows where reviewing changes file-by-file is a frequent necessity, splitdiff serves as a straightforward yet highly effective helper script. Its design embodies the Unix philosophy of providing small, specialized tools that perform one task well, thereby facilitating more modular and manageable development processes.