gitでcommit hashを指し示すとき、HEAD^やHEAD~といった表現をするときがある。
gitは各commitが一つ前のcommit ()のhashを保持しているので、HEAD^と書くと一つ前のcommitが参照できる。
しかしながら一つ前のcommitは1つとは限らず、merge commitでは2つ以上のcommitを記録している。
merge commitがHEADのときにHEAD^と指定すると果たしてどのcommitが指し示されるのか。
これは2つ以上のcommitに順番があって、^ (キャレット) のあとに数字を指定することで、何番目のcommitを指し示すかを表せる。
Pro Gitに詳しく載っている
https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection
You can also specify a number after the ^ to identify which parent you want; for example, d921970^2 means “the second parent of d921970.” This syntax is useful only for merge commits, which have more than one parent — the first parent of a merge commit is from the branch you were on when you merged (frequently master), while the second parent of a merge commit is from the branch that was merged (say, topic):
feature branchでのcommitをmasterに向けてマージしたmerge commitがHEADのとき、HEAD^だとmasterのほうのcommit、HEAD^2だとmergeしたほうのcommitを指し示すらしい。
ここら辺の話は日本語だと以下のブログ記事が説明してくれている。
https://masuyama13.hatenablog.com/entry/2020/08/21/231120