Progress:
TIER 2 · MODULE 54· Intermediate

git patch-id

Same change, different commit IDs — patch-id matches them up.

🎯 What & why

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.

🧠 Mental model

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.

🛠️ Synopsis

git patch-id [--stable | --unstable | --verbatim] < <mbox-or-diff>
# Output: <patch-sha1> <commit-sha1>

🎚️ Switches & options

FlagWhat it does
--stableDefault. Sums per-hunk hashes so reordered hunks still match
--unstableHash depends on hunk order; faster, matches pre-1.9 behavior
--verbatimHash the diff bytes literally - whitespace and order matter
(stdin)Reads git format-patch mbox or git diff output; one or many patches

💡 Use cases

🧪 Examples

Patch-id of a single commit
git show HEAD | git patch-id
All commits in a range
git format-patch --stdout origin/main..HEAD | git patch-id --stable
Find a matching upstream commit
git log --format=%H origin/main | while read c; do git show $c | git patch-id; done | grep <id>
Order-sensitive comparison
git diff A B | git patch-id --verbatim

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.