Skip to content
Latchkey

git hash-object: Usage, Options & Common CI Errors

git hash-object returns the SHA Git would assign to a piece of content.

This plumbing command is how you compute a blob id without committing, write loose objects directly, or verify that a file matches an expected object id in a pipeline.

What it does

git hash-object reads content from a file or standard input, computes the object id Git would give it (a blob by default), and optionally writes the object into the object database with -w.

Common usage

Terminal
git hash-object file.txt
git hash-object -w file.txt        # also write into .git/objects
echo "hello" | git hash-object --stdin
git hash-object -t blob --stdin < data.bin

Options

FlagWhat it does
-wWrite the object into the database
--stdinRead content from standard input
-t <type>Object type (blob, tree, commit, tag)
--path <file>Apply filters as if at this path
--no-filtersSkip clean/CRLF filters

Common errors in CI

Line-ending and filter settings can change the computed hash: a file run through autocrlf or a clean filter hashes differently than its on-disk bytes. Use --no-filters for byte-exact hashing, and remember -w needs to run inside a repository so .git/objects exists.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →