LinuxCommandLibrary

git-patch-id

Compute patch ID for change tracking

SYNOPSIS

git patch-id [--stable]

PARAMETERS

--stable
    (Optional) This option ensures the patch ID is computed using the "stable" algorithm. It has been the default behavior since Git version 2.12 and earlier, and the old, less stable algorithm is no longer available. Explicitly specifying it has no effect on modern Git versions but might be used for clarity or compatibility with very old scripts.

DESCRIPTION

git-patch-id reads a patch from standard input and generates two SHA1 hashes on standard output: a "patch ID" and a "subject ID". The "patch ID" is a stable identifier for the patch's content, computed from the diff after normalizing it (removing leading whitespace, line numbers from hunk headers, etc.). This ensures that minor changes like reformatting or shifting line numbers don't alter the ID. It's primarily used by git-am to detect if a patch has already been applied, preventing redundant application.

The "subject ID" is a SHA1 hash of the patch's subject line.

CAVEATS

The --stable option is now the default and has no practical effect on modern Git versions (2.12+). The older, less stable patch ID algorithm is no longer supported. The patch ID is a heuristic for content comparison and should not be relied upon for cryptographic security.

HOW PATCH ID IS COMPUTED

The patch ID is derived from the diff content itself. Git normalizes the diff by ignoring leading whitespace and stripping line numbers from hunk headers before hashing. This makes the ID resilient to common formatting variations in patches.

USE CASES

Beyond git-am's automatic detection, git-patch-id can be used manually by developers to check for duplicate patches in a series or to uniquely identify specific changes independent of their commit hash or authorship details.

HISTORY

The git-patch-id command was introduced early in Git's history to help with patch management. Initially, it used an algorithm that could be sensitive to minor format changes. The more robust "stable" algorithm was introduced and eventually became the default around Git 2.12 (released in 2017). The old algorithm was then removed, making --stable a redundant, though harmless, flag.

SEE ALSO

Copied to clipboard