this post was submitted on 05 Oct 2026
90 points (92.5% liked)
Programming
29120 readers
260 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I tried to implement my own git from scratch. And when I got to choose a hashing algorithm, I reached the exact same conclusion as the author pretty fast.
The hashing algorithm doesn't really matter as long as it's good enough to prevent accidental collisions. And if there is a collision, it is extremely easy to check.
If you are about to create a new object and an object with that hash already exists, you compare the 2 objects. If they are the same, nothing happened. If they are different, you just found a collision. Throw some obscure error that will only be witnessed once in the lifetime of the universe and be done with it. Tell the user to change a single bit of the input and be done with it.
The purpose of object hashes in git was never to provide security. Security is achieved through other means.
Let's explicit this: you can, and should, sign your commits if you want security (no commit tampering). You need to:
gpg --full-generate-keygit config --global user.signingkey [public key ID]git config --global commit.gpgsign trueNote that I used
--globalhere but you can do without to sign on a per-project basis.Also
gpgUX is terrible, to find the[public key ID]use the commandgpg --list-keys, it should looks like:Last, if you want to save/backup you keys the default location of
gpgfiles is~/gnupgor you can export keys withgpg --export [key ID] > path/to/file.keyfor the public part andgpg --export-secret-keys [private key ID]for the private part. Both export can have a-aor--armorargument to output as base64 text instead of raw binary.[private key ID]can be found withgpg --list-secret-keys.EDIT: after writing this I checked https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work and TIL you can sign tags too.
EDIT 2: you can also use your ssh key to sign ->
git config --global gpg.format ssh(I am less inclined to do this as you won't have subkeys and expiration date but this would be simplier indeed)If you want to avoid the gpg mess, you can actually also configure gut to sign with your SSH key.