LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-hash-object

Compute object ID value

TLDR

Compute object hash
$ git hash-object [file]
copy
Compute and store object
$ git hash-object -w [file]
copy
Hash from stdin
$ echo "[content]" | git hash-object --stdin
copy
Specify object type
$ git hash-object -t [blob] [file]
copy

SYNOPSIS

git hash-object [options] [file...]

DESCRIPTION

git hash-object computes the object ID (SHA-1, or SHA-256 in repositories using that format) for a file and optionally stores it in the Git object database. This low-level plumbing command exposes Git's internal object storage mechanism.The command calculates the hash by formatting the file content as a Git object (with type and size header), then hashing it. With the -w option, it also writes the object to .git/objects/, making it part of the repository even if not yet referenced by any commit. The --stdin option enables hashing content from pipes or scripts; --stdin-paths reads a list of file paths instead.

PARAMETERS

-w

Write object to database.
--stdin
Read from stdin.
-t type
Object type (blob, commit, tree, tag).
--path path
Hash as if at path.
--no-filters
Don't apply filters.
--stdin-paths
Read file paths from stdin, hashing each in turn.
--literally
Allow hashing content that wouldn't form a valid object (debugging).

INSTALL

sudo apt install git
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

CAVEATS

Without -w, the object is only hashed, not stored. Filters (like `clean` in `.gitattributes`) are applied by default unless --no-filters is given, which can change the resulting hash.

HISTORY

git hash-object is a core plumbing command present since Git's earliest releases, exposing the object hashing used internally for blobs, trees, and commits.

SEE ALSO

RESOURCES

Copied to clipboard
Kai