◆ 同じ親に対して変更点とメッセージが一緒で author と commiter の情報が一緒なら同じハッシュ値 

cherry pick したときや メッセージのみコミットで同じメッセージ入れた時など同じはずなのにハッシュは違うってことがあります

ハッシュの計算には

  • commit (変更したファイルとメッセージ)
  • author 情報
  • commiter 情報
  • 親コミットの SHA1

が使われてるようです


ということで 同じハッシュ値になるコミットを作ってみます
やることはこれだけ
GIT_COMMITTER_DATE="2017-05-01 09:00:00 +0900" git commit --allow-empty -m "first commit" --date "2017-05-01 09:00:00 +0900"
git branch a
git checkout a
GIT_COMMITTER_DATE="2017-05-02 09:00:00 +0900" git commit --allow-empty -m "will duplicate hash" --date "2017-05-02 09:00:00 +0900"
git log
git checkout master
GIT_COMMITTER_DATE="2017-05-02 09:00:00 +0900" git commit --allow-empty -m "will duplicate hash" --date "2017-05-02 09:00:00 +0900"
git log
git log a



まずは空のリポジトリを作ります
そこにとりあえず最初のコミットをします
user@desktop MINGW64 ~/Desktop/gittest/repo (master)
$ GIT_COMMITTER_DATE="2017-05-01 09:00:00 +0900" git commit --allow-empty -m "first commit" --date "2017-05-01 09:00:00 +0900"
[master (root-commit) 6c9158e] first commit
Date: Mon May 1 09:00:00 2017 +0900

first commit のところに a ブランチを作ってコミットします
user@desktop MINGW64 ~/Desktop/gittest/repo (master)
$ git branch a

user@desktop MINGW64 ~/Desktop/gittest/repo (master)
$ git checkout a

user@desktop MINGW64 ~/Desktop/gittest/repo (a)
$ GIT_COMMITTER_DATE="2017-05-02 09:00:00 +0900" git commit --allow-empty -m "will duplicate hash" --date "2017-05-02 09:00:00 +0900"
[a 0769aa0] will duplicate hash
Date: Tue May 2 09:00:00 2017 +0900

user@desktop MINGW64 ~/Desktop/gittest/repo (a)
$ git log
commit 0769aa0e238b2d677b2d22b83ec54c6f06c933e7
Author: user <mail@ddre.ss>
Date:   Tue May 2 09:00:00 2017 +0900

    will duplicate hash

commit 6c9158e88aa5481edba46a6d2dccfd9d0017ccc6
Author: user <mail@ddre.ss>
Date:   Mon May 1 09:00:00 2017 +0900

    first commit

次に master に戻ってそこに同じ内容のコミットを行います
user@desktop MINGW64 ~/Desktop/gittest/repo (a)
$ git checkout master
Switched to branch 'master'

user@desktop MINGW64 ~/Desktop/gittest/repo (master)
$ GIT_COMMITTER_DATE="2017-05-02 09:00:00 +0900" git commit --allow-empty -m "will duplicate hash" --date "2017-05-02 09:00:00 +0900"
[master 0769aa0] will duplicate hash
Date: Tue May 2 09:00:00 2017 +0900

user@desktop MINGW64 ~/Desktop/gittest/repo (master)
$ git log
commit 0769aa0e238b2d677b2d22b83ec54c6f06c933e7
Author: user <mail@ddre.ss>
Date:   Tue May 2 09:00:00 2017 +0900

    will duplicate hash

commit 6c9158e88aa5481edba46a6d2dccfd9d0017ccc6
Author: user <mail@ddre.ss>
Date:   Mon May 1 09:00:00 2017 +0900

    first commit

user@desktop MINGW64 ~/Desktop/gittest/repo (master)
$ git log a
commit 0769aa0e238b2d677b2d22b83ec54c6f06c933e7
Author: user <mail@ddre.ss>
Date:   Tue May 2 09:00:00 2017 +0900

    will duplicate hash

commit 6c9158e88aa5481edba46a6d2dccfd9d0017ccc6
Author: user <mail@ddre.ss>
Date:   Mon May 1 09:00:00 2017 +0900

    first commit

ログを見ると master ブランチと a ブランチの 2 つめのコミットのハッシュ値が一緒です

通常 あるコミットを指すブランチが 2 つあって それぞれに同じ変更したコミットをしても別のハッシュ値になるので 「Y」 字の分岐になります
ですが これでは同じハッシュになるので 「|」 状になって 2 つのブランチが同じところを指してることになります

親コミット・ author の情報・ commiter の情報 がすべて一緒なら master にコミットして そこに a ブランチを作ったのと実質一緒なのでハッシュ値が一緒ですが何も問題はありません

ハッシュ値が一緒で問題が起きるのは 親コミットが違ったりコミット内容が違ったりするときに偶然ハッシュ値が一緒になるときだけのようです