Where the SHA-1/SHA-256 magic happens.
git hash-object computes the object ID Git would assign to a piece of content, and (with -w) actually writes that blob into the object database. It's the SHA factory.
Git hashes 'header + NUL + content' where header is e.g. 'blob 1234'. Same bytes -> same SHA, deterministically. -w just stores the result under .git/objects/.
git hash-object [-t <type>] [-w] [--path=<file>] [--no-filters] [--stdin] [--] <file>...
git hash-object [-t <type>] [-w] [--stdin-paths] [--no-filters]
git hash-object --literally [-t <type>] [-w] --stdin| Flag | What it does |
|---|---|
-t <type> | Object type (blob, tree, commit, tag); default blob. |
-w | ⚠️ Write the object into the object DB, not just print its SHA. |
--stdin | Read content from stdin instead of a file argument. |
--stdin-paths | Read a list of paths from stdin and hash each. |
--no-filters | Skip clean filters and CRLF normalization; hash bytes as-is. |
--path=<file> | Pretend the content lives at <file> for filter/attribute purposes. |
--literally | ⚠️ Allow malformed/oversize objects; for forensic or test use only. |
git hash-object README.mdgit hash-object -w big.binecho hello | git hash-object --stdin --path=greet.txtfind src -type f | git hash-object --stdin-paths -wgit cat-file -p <sha> to immediately verify what you wrote.Hit each option, then Check answers. Score is recorded; Next is always open.