Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

PSA: You can safely refer to those long "commit-ish" identifiers using just the first 7 or 8 chars (eg `88113a64`) without real risk of collision. Let alone in examples / gists!


Git will even warn you if the hash prefix you provide is ambiguous!

I had a collision the other day on a mediums-sized when using a 6 character hash and was surprised. Git let me know and told me which objects collided.


Wow, that's super unlikely. How many commits did the repo have?

According to [1] using 3 letters you'd need at least 72 commits to have at least 50% chance to observe a clash. Using 6 letters you'd need at least 3977 commits, lol.

[1] https://en.wikipedia.org/wiki/Birthday_problem#The_generaliz...


I’ve been using git for going on ten years. You don’t think I can pull off just one commit/day?

I use six character hashes, I don’t recall that I’ve had a collision yet. But I guess I’m “due”. :-)


How is that unlikely? 4k commits is nothing. Any project with a dozen developers is going to reach that easily.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: