git-hash-object
Calculate object ID and optionally store object
TLDR
Compute the object ID without storing it
Compute the object ID and store it in the Git database
Compute the object ID specifying the object type
Compute the object ID from stdin
SYNOPSIS
git hash-object [-t <type>] [-w] [--stdin-paths] [--no-filters] [--literally] [--stdin] [--] <file>...
git hash-object --stdin-paths [-w] [--no-filters] [--literally]
PARAMETERS
-t <type>
Specify object type: blob, commit, tag, or tree (defaults to blob for stdin, file type otherwise).
-w
Write object to the Git object database (still prints hash).
--stdin-paths
Read paths from stdin (one per line) and hash those files instead of stdin data.
--no-filters
Skip smudge/clean filters and CRLF conversion during hashing.
--literally
Hash content literally, without line-ending normalization.
--stdin
Read object data directly from standard input (default if no files given).
DESCRIPTION
The git hash-object command is a low-level Git plumbing tool that computes the object ID (SHA-1 hash) for given content as it would be stored in Git's object database. It supports creating hashes for blobs, trees, commits, or tags by specifying the type with -t. By default, it reads files and treats them as blobs, but --stdin allows hashing data piped from standard input.
This command is essential for scripting Git operations, verifying object integrity, or manually constructing objects without full repository commands. When used with -w, it not only prints the hash but also stores the object in .git/objects, enabling reuse by other Git tools.
Options like --no-filters bypass content filters (e.g., CRLF conversion or textconv), and --literally prevents line-ending normalization, ensuring exact hashing. --stdin-paths hashes multiple files listed on stdin, useful for batch operations.
Common use: Verify a blob hash with echo 'content' | git hash-object --stdin. Output is always the 40-character hexadecimal hash in lowercase.
CAVEATS
Hashes use the repository's object hash algorithm (SHA-1 by default; SHA-256 in newer repos). No support for specifying hash algorithm directly. Objects written with -w are loose; pack later with git repack.
EXAMPLE: SIMPLE BLOB
echo 'Hello World' | git hash-object --stdin
Output: 95919488222bb8b55a9a4dfe89e9a8635a669db3
EXAMPLE: WRITE OBJECT
echo 'data' | git hash-object -t blob -w --stdin
Creates loose blob object and prints its hash.
HISTORY
Introduced in Git 0.99 (April 2005) as part of Linus Torvalds' initial Git release. Core plumbing since Git 1.0 (2006), with options like --stdin-paths and --literally added in later versions (e.g., Git 1.7+ for filters). Remains unchanged in core functionality across Git 2.x.
SEE ALSO
git-cat-file(1), git-update-index(1), git-mktree(1), git-commit-tree(1)


