Same change, different commit IDs — patch-id matches them up.
Computes a stable, content-only hash of a patch so that the same logical change made on different branches (with different commit IDs and timestamps) hashes to the same value.
Strip out everything that varies between equivalent patches - context, line numbers, file headers' noise, whitespace order - then SHA1 what's left. Two cherry-picks of the same change get the same patch-id.
git patch-id [--stable | --unstable | --verbatim] < <mbox-or-diff>
# Output: <patch-sha1> <commit-sha1>
| Flag | What it does |
|---|---|
--stable | Default. Sums per-hunk hashes so reordered hunks still match |
--unstable | Hash depends on hunk order; faster, matches pre-1.9 behavior |
--verbatim | Hash the diff bytes literally - whitespace and order matter |
(stdin) | Reads git format-patch mbox or git diff output; one or many patches |
git cherry does)git show HEAD | git patch-idgit format-patch --stdout origin/main..HEAD | git patch-id --stablegit log --format=%H origin/main | while read c; do git show $c | git patch-id; done | grep <id>git diff A B | git patch-id --verbatim--stable unless you have a specific reason - it's what git cherry and git rebase use.format-patch --stdout (not raw diff) when you want the commit-id field populated correctly.--verbatim hashes whitespace and line endings; CRLF/LF mismatches will diverge silently.diff and format-patch output can flip results under --verbatim.Hit each option, then Check answers. Score is recorded; Next is always open.