Skip to content
The Git Crypt

/static/cripta/en/ossada/hash-object/

Menu

GIT-013 · Plumbing

git hash-object

Computes a file's identity — and, if asked, deposits it in the vault.

It is git's first operation, served raw: given some content, compute the hash that identifies it. Without -w nothing is written — the command merely answers "if this file entered the vault, this would be its name". With -w, the blob is actually deposited.

It earns its keep as lesson and as trick: the lesson is that the same content always has the same hash, on any machine; the trick is checking whether a loose file is identical to something already versioned, comparing identities instead of bytes.

$ git hash-object helpers.go
6c9f2e41b0a8d3f7c5e21a94d8b06f3a7c4e9d12
$ echo 'oi' | git hash-object --stdin
8b1e9f0a3c7d5b2e4f6a8c0d9b3e5f7a1c4d6e80
The name the content would bear, computed without writing.