git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git commit hash clash prevention

From
Thomas Rast <trast@student.ethz.ch>
Date
Oct 2, 2008, 09:18 UTC
Message-ID
<200810021118.15313.trast@student.ethz.ch>
In-Reply-To
<20081002085358.GA5342@lapse.rw.madduck.net>
martin f krafft wrote:
Show 10 quoted lines
> the other day during a workshop on Git, one of the attendants asked
> about the scenario when two developers, Jane and David, both working
> on the same project, both create a commit and the two just so happen
> to have the same SHA-1. I realise that the likelihood of this
> happening is about as high as the chance of <insert witty joke
> here>, but it *is* possible, isn't it? Even though this is thus
> somewhat academic, I am still very curious about it.
> 
> What happens when David now pulls from Jane? How does Git deal with
> this?
There are two cases:
* The commits are exactly identical.  This won't happen in your
  scenario, but is still theoretically possible if you commit the same
  tree with the same author info, timestamps, etc. on two different
  machines.  Then there is no problem, because they really are the
  same.
* They're not identical, but there is a hash collision.  Git will
  become very confused because it only ever saves one of them.  (I
  suppose it'd "only" corrupt the DAG if the two are commits, but in
  the general case a commit could collide with a tree etc.)
  However, the expected number of objects needed to get a collision is
  on the order of 2**80 (http://en.wikipedia.org/wiki/Birthday_attack),
  and since there are (very roughly) 2**25 seconds in a year and 2**34
  years in the age of the universe, that still leaves you with 2**21
  ages of the universe to go.
(I hope I did the counting right...)
> I imagine it'll be able to distinguish the two commits based on
> metadata, but won't the DAG get corrupted?
No, it does not distinguish between objects in any way but the SHA1.
- Thomas
-- 
Thomas Rast
trast@student.ethz.ch
Previous: martin f krafftNext: Jean-Luc Herren
Message 2 of 7 in “Git commit hash clash prevention”
  1. martin f krafftOct 2, 2008
  2. Thomas RastOct 2, 2008
  3. Jean-Luc HerrenOct 2, 2008
  4. Johannes SchindelinOct 2, 2008
  5. Jakub NarebskiOct 2, 2008
  6. Johannes SchindelinOct 2, 2008
  7. Stephan BeyerOct 2, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.