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.
git diff-pairs Syntax:
Section titled “git diff-pairs Syntax:”git diff-pairs -z [<diff-options>]Options:
Section titled “Options:”| Option | Description |
|---|---|
| -z | Process NUL-terminated input from stdin |
| -p, —patch | Generate patch output |
| -s, —no-patch | Suppress diff output |
| —stat | Show diffstat |
| -U | Generate diffs with context |
| —raw | Generate raw format output |
| —color | Show colored diff |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| (stdin) | NUL-terminated raw diff input from other commands |
git diff-pairs Command Samples:
Section titled “git diff-pairs Command Samples:”Basic usage with diff-tree pipeline
Section titled “Basic usage with diff-tree pipeline”git diff-tree -z -r -M HEAD~1 HEAD | git diff-pairs -zProcesses raw diff data from diff-tree and generates patch output.
Generate patch format diffs
Section titled “Generate patch format diffs”git diff-tree -z -r HEAD~1 HEAD | git diff-pairs -z -pExplicitly generates patch format diffs from the pipeline input.
Progressive diff computation
Section titled “Progressive diff computation”git diff-tree -z -r --no-patch HEAD~1 HEAD | git diff-pairs -zCompute 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:
git diff-tree -z -r HEAD~1 HEAD | git diff-pairs -zWhat 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”- Separating tree diff computation from patch generation in advanced workflows
- Enabling progressive diff computation over multiple invocations
- Building custom Git pipelines and integrations
- Scripting diff processing with rename and move detection
- Optimizing performance for large repository diff operations