Progress:
TIER 3 · MODULE 05· Expert

git hash-object

Where the SHA-1/SHA-256 magic happens.

🎯 What & why

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.

🧠 Mental model

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/.

🛠️ Synopsis

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

🎚️ Switches & options

FlagWhat 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.
--stdinRead content from stdin instead of a file argument.
--stdin-pathsRead a list of paths from stdin and hash each.
--no-filtersSkip 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.

💡 Use cases

🧪 Examples

Hash without writing
git hash-object README.md
Write a blob into the DB
git hash-object -w big.bin
Hash from stdin, treat as file path
echo hello | git hash-object --stdin --path=greet.txt
Batch hash a file list
find src -type f | git hash-object --stdin-paths -w

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.