0

I have a problem in Git log; it seems that my team lost some changes.

I am questioning if two merge commits can share a same commit Hash ID. For example, a merge commit merges commit A and commit B yesterday. In Git log, another commit merges commit C and commit B today. Can it happen in normal situation?

[Update] The Git log looks like below. I am not sure if it IS SHA-1 collision; my concern is that I can see two merges that have the same ccccccc commit. I hope it have my question clear.

=============================================================
commit yyyyyyy
Merge: aaaaaaa ccccccc
Author: Joe myself
Date:   Today some time

    Merge remote-tracking branch 'origin/a-branch' into feature-branch

commit xxxxxxx
Merge: bbbbbbb ccccccc
Author: Kim
Date:   Two days ago some time

    Merge branch 'develop' of https://..... into her-branch

commit ccccccc
Merge: ddddddd eeeeeee
Author: Joe myself
Date:   Two days ago some time

    Merge remote-tracking branch 'origin/another-branch' into a-branch
=============================================================
Joe Cho
  • 149
  • 1
  • 7
  • 1
    It's really unlikely as sha1 is a cryptographic hash function. – MrTux Aug 27 '15 at 00:07
  • See this question. http://stackoverflow.com/questions/1867191/probability-of-sha1-collisions – Jeremy Fortune Aug 27 '15 at 00:21
  • possible duplicate of [How would git handle a SHA-1 collision on a blob?](http://stackoverflow.com/questions/9392365/how-would-git-handle-a-sha-1-collision-on-a-blob) – Matt Clark Aug 27 '15 at 14:52
  • How can it be a collision if each one of the 3 merge commits has a different id? A commit can be merged into many commits, you said it in your question: B is merged with both A and C, so B is ccccccc. My answer was correct: a collision cannot happen. – FelipeC Aug 28 '15 at 17:23
  • @FelipeC For sure, I don't think it's a SHA-1 collision. You got my point; my question was 'can a commit be merged into many commits?'. – Joe Cho Aug 28 '15 at 21:50

1 Answers1

2

See this post that explains the chances of a collision between two SHA-1 hashes; this situations is very unlikely, however still not entirely impossible.

Most visual git explorers will only show the first 8 digits of the hash, which while still very unlikely, is much more probable then the whole hash collision.

Run git log and examine your commits, my thought is that you may have misread something - I'll give you an award if you actually did get a collision :D

If you want, [edit] your post to add in the contents of the git log where you think you may have an issue for us to better understand your issue.

Cheers.

Community
  • 1
  • 1
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • 2
    Downvoter, please explain your reasoning? If I missed something, or said something incorrectly, I would like to know. Cheers. – Matt Clark Aug 27 '15 at 14:06
  • 2
    Not the downvoter, but to give a sense of "_very_" unlikely, if you were doing one commit per second since the Big Bang you'd have reason for concern about hash collisions. To descend from the ludicrous to a merely ridiculous interval, your chances of a collision are down around 6.84227766e-20 if you'd been doing one per second since Lucy was an ape. "Astronomically small" doesn't begin to cover that. It's literally a rounding error on zero. – jthill Aug 27 '15 at 18:32