Skip to content

diff-pairs Git Command Guide

The git diff-pairs command is used to compare the content and mode of provided blob pairs. It reads NUL-terminated raw diff data from stdin and generates patch output. This enables breaking up the traditional diff pipeline into separate phases, allowing for progressive computation of diffs.

Terminal window
git diff-pairs -z [<diff-options>]
OptionDescription
-zProcess NUL-terminated input from stdin
-p, —patchGenerate patch output
-s, —no-patchSuppress diff output
—statShow diffstat
-U, —unified=Generate diffs with context
—rawGenerate raw format output
—colorShow colored diff
ParameterDescription
(stdin)NUL-terminated raw diff input from other commands
Terminal window
git diff-tree -z -r -M HEAD~1 HEAD | git diff-pairs -z

Processes raw diff data from diff-tree and generates patch output.

Terminal window
git diff-tree -z -r HEAD~1 HEAD | git diff-pairs -z -p

Explicitly generates patch format diffs from the pipeline input.

Terminal window
git diff-tree -z -r --no-patch HEAD~1 HEAD | git diff-pairs -z

Compute tree diffs upfront with rename info, then generate patches progressively.

How do I use git diff-pairs in a typical workflow?

Section titled “How do I use git diff-pairs in a typical workflow?”

To use git diff-pairs, pipe NUL-terminated raw diff data from git diff-tree:

Terminal window
git diff-tree -z -r HEAD~1 HEAD | git diff-pairs -z

What input format does diff-pairs require?

Section titled “What input format does diff-pairs require?”

git diff-pairs requires NUL-terminated raw diff format input from stdin, typically generated by git diff-tree -z -r —raw.

How does diff-pairs enable progressive diff computation?

Section titled “How does diff-pairs enable progressive diff computation?”

By computing file pairs and rename information upfront with diff-tree, then feeding them to diff-pairs, it allows generating patches incrementally during multiple invocations.

What’s the advantage of using diff-pairs over git diff-tree -p directly?

Section titled “What’s the advantage of using diff-pairs over git diff-tree -p directly?”

git diff-pairs separates the tree traversal phase from patch generation, allowing for more efficient processing and potential progress reporting during long diffs.

Can NUL bytes be used for batch processing in diff-pairs?

Section titled “Can NUL bytes be used for batch processing in diff-pairs?”

Yes, a single NUL byte in the input stream tells diff-pairs to compute diffs for file pairs up to that point, writing a NUL to output between batches.

What are the limitations of pathspecs with diff-pairs?

Section titled “What are the limitations of pathspecs with diff-pairs?”

Pathspecs are not supported by diff-pairs. Pathspec limiting should be performed by the upstream command generating the raw diffs.

Applications of the git diff-pairs command

Section titled “Applications of the git diff-pairs command”
  1. Separating tree diff computation from patch generation in advanced workflows
  2. Enabling progressive diff computation over multiple invocations
  3. Building custom Git pipelines and integrations
  4. Scripting diff processing with rename and move detection
  5. Optimizing performance for large repository diff operations