git-patch-id
Compute patch ID for change tracking
SYNOPSIS
git patch-id [--text | --stable | --unstable] [patch ...]
PARAMETERS
--stable
Compute order-independent patch ID (ignores hunk ordering)
--unstable
Compute legacy hunk-order-dependent patch ID (default)
--text
Treat binary files as text (don't skip them)
DESCRIPTION
git patch-id is a Git plumbing command that generates a unique 40-character SHA-1 identifier for a patch, ensuring equivalence despite variations in whitespace, line numbers, filenames, or hunk order (in stable mode). It reads patches from standard input or files, normalizing content by stripping timestamps, collapsing whitespace changes, zeroing line numbers, and handling context lines.
This ID is crucial for Git internals: git rebase uses it to detect already-applied commits during interactive rebases; git bisect skips identical patches; git am and git cherry-pick verify application status; git format-patch series track order-independently with stable mode.
Three computation modes exist: default --unstable (hunk-order dependent, legacy); --stable (order-independent, recommended for new code); --text (processes binaries as text). Output is one ID per input patch, prefixed by any stdin filename if piped.
Ideal for scripting patch series validation, avoiding duplicates in quilt-like workflows or Git's patchflow tools. Limitations include sensitivity to semantic changes like added/removed lines.
CAVEATS
Modes --stable and --unstable produce incompatible IDs; switch consistently. Ignores binary diffs unless --text. Not for human-readable output; IDs change with semantic patch alterations. Requires clean patches.
EXAMPLE
git show abc123 | git patch-id --stable
Outputs: def4567890abcdef1234567890abcdef12345678
NORMALIZATION STEPS
Strips +++ --- timestamps/filenames; normalizes whitespace; zeros line numbers; collapses empty context; sorts hunks in stable mode.
HISTORY
Introduced in Git 1.6.1 (February 2008) with unstable algorithm for basic patch tracking. --stable mode added in Git 2.9.0 (March 2016) for reliable series handling, addressing hunk-reordering issues in rebases. Default remains --unstable for compatibility; widely used in Git core since.
SEE ALSO
git-am(1), git-apply(1), git-bisect(1), git-cherry(1), git-format-patch(1), git-rebase(1)


