@kyanny's blog

My thoughts, my life. Views/opinions are my own.

Git: patch id について

git rebase した時に commit sha1 が違うが diff が同一のコミットが自動的に skip された。ふと、 Git は一体どうやってコミットの同一性を判断しているのだろう、と思って少し調べたところ、「パッチ ID」というものを使っているらしい。

Git は、コミットの SHA-1 チェックサム以外にもうひとつのチェックサムを計算しています。これは、そのコミットで投入されたパッチから計算したものです。 これを「パッチ ID」と呼びます。

Git - リベース

It turns out that in addition to the commit SHA-1 checksum, Git also calculates a checksum that is based just on the patch introduced with the commit. This is called a “patch-id”.

Git - Rebasing

git-patch-id というコマンドで調べることができる。

Git - git-patch-id Documentation

例: ea852c2e8696230decb0ab1d053557445023fb172f415a567355e7b672109797436393d6cc58f388 は同じ diff を持つ異なるコミット。

$ git show ea852c2e | git patch-id
aef46abb5e284e605d56bcbcaaa58b66c0711006 ea852c2e8696230decb0ab1d053557445023fb17
$ git show 2f415a56 | git patch-id
aef46abb5e284e605d56bcbcaaa58b66c0711006 2f415a567355e7b672109797436393d6cc58f388

The first string is the patch ID, and the second string is the commit ID.

パッチ ID は同じであることがわかる。