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

Re: git behaviour question regarding SHA-1 and commits

From
VVvinassa vinassa <vinassa.vinassa@gmail.com>
Date
Nov 13, 2011, 22:14 UTC
Message-ID
<CAM6yGmBgpWzC_jgeyKbWCU-_NJ2NCjpOBHWtTtKyZd95P1xU=A@mail.gmail.com>
In-Reply-To
<20111113182757.GA15194@elie.hsd1.il.comcast.net>
Hi, thanks for the responses, I get the picture. Some comments below still.
On Sun, Nov 13, 2011 at 7:27 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 24 quoted lines
>
> Hi Vinassa,
>
> vinassa vinassa wrote:
>
> > I am wondering about how git behaves currently, if I kinda win the
> > lottery of the universe, and happen to create a commit with a SHA-1
> > that is already the SHA-1 of another commit in the previous history.
> > However improbable.
>
> That would be great!  You could definitely get an academic paper out
> of it.
>
> > Would that be detected, so that I could just add a newline, and then
> > commit with a different resulting SHA-1,
> > would I just lose one of those commits (hopefully the new one), would
> > I end up with a corrupted repository?
>
> I suspect that one of the two commits would "win" the right to be
> shown by commands like "git log".  A commit made after one of the
> commits participating in the hash collision might be stored as a delta
> against the wrong one in the pack, producing errors when you try to
> access it (which is good, since it helps you find the hash collision
> and you can get a paper and prizes).

After cashing in the prizes, I would be able then to git reset --soft, add a newline, make another commit and go on with my work, right? No screw up big enough to demand restoring from backups.

> Though I haven't tested.  It would be nice to have an md5git (or even
> truncated-sha1-git) program to test this kind of thing with.

Yes, would be nice. I'll try to see if I can wrap my mind around the test infrastructure.

> Thanks and hope that helps,
> Jonathan

Thank you for your patience, I understand I should not worry about this, but this has made me even more curious about what would happen..

Vinassa
Previous: Jonathan NiederNext: Jeff King
Message 6 of 11 in “git behaviour question regarding SHA-1 and commits”
  1. vinassa vinassaNov 13, 2011
  2. Ævar Arnfjörð BjarmasonNov 13, 2011
  3. Junio C HamanoNov 14, 2011
  4. Jeff KingNov 14, 2011
  5. Jonathan NiederNov 13, 2011
  6. vinassa vinassaNov 13, 2011
  7. Jeff KingNov 14, 2011
  8. Victor EngmarkNov 14, 2011
  9. Jeff KingNov 14, 2011
  10. Dmitry PotapovNov 13, 2011
  11. Johannes SixtNov 14, 2011

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.