Git Object ID (hash-object)
Work out the git object id of a blob, tree, commit or tag in both SHA-1 and SHA-256, with the header git hashes and the loose object path.
How to use
- Leave the type on blob, type or paste the contents, and read the SHA-1 and SHA-256 ids — this is git hash-object with no flags.
- Switch the body to file to hash a file from your disk exactly as it is, byte for byte, with no line-ending conversion.
- Use hex for anything binary, including a tree body, whose entries are a mode, a name, a NUL and a raw id.
- Choose commit or tag to hash an object body you already have, the way git hash-object -t commit --literally does.
- Paste an id you are trying to reproduce into the expected field; an abbreviation is enough, and the tool says which algorithm matched.
About this tool
ShowHide
This is what git hash-object does, in a browser tab. A git object is not named after the hash of its contents: it is named after the hash of the type, a space, the byte count, a NUL, and then the contents, which is why a plain sha1sum of a file never matches the id git prints for it. Both ids are shown, because a repository created with the default settings names objects with SHA-1 while one created with object-format sha256 names them with SHA-256, and the two spaces are separate — there is no converting an id from one to the other. The header and its bytes are on screen so the rule can be read rather than trusted, and a few of the results are constants worth recognising: an empty blob is always e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 and an empty tree always 4b825dc642cb6eb9a060e54bf8d69288fbee4904. The id covers the type, the length and the bytes and nothing else, so the file name and the mode are not in it; they sit in the tree entry that points at the blob, which is how two identical files anywhere in a repository share one object. A trailing newline is content and changes the id. So do CRLF line endings, and that is the usual reason a locally computed id disagrees with git: with core.autocrlf or a text attribute in effect, the blob git stores holds LF while the file on disk holds CRLF, so the tool warns when it sees a CRLF in the body. Tree bodies are binary — a mode, a space, a name, a NUL, then a raw twenty-byte id — so a tree is entered as hex rather than text. Paste an id, whole or abbreviated, to have it checked against both results.
Frequently asked questions
Why doesn't sha1sum give the same id?
Because git hashes a header first. The input to the hash is the object type, a space, the length of the body in bytes, a zero byte, and then the body, so sha1sum of the same file is a different number entirely. Prepend the header yourself — printf 'blob 11\0hello world' | sha1sum — and it matches.
Does the file name change the id?
No. A blob is contents and nothing else, which is why a repository with the same file in twenty places stores one object and why renaming a file does not create a new blob. Names, modes and the directory structure live in tree objects, and those trees are what a commit points at. If two files in your project have the same id, they are byte-identical.
Why does my id differ from what git shows for the same file?
Almost always line endings. With core.autocrlf true on Windows, or a text attribute in .gitattributes, git converts CRLF to LF on the way in, so the blob it stores is not the bytes on your disk. Other clean filters — a smudge/clean pair, or the ident attribute — have the same effect. Hashing the file here gives the id of the file as it exists; git rev-parse HEAD:path gives the id of what was stored.
What about a SHA-256 repository?
git init --object-format=sha256 makes a repository that names objects by SHA-256 of the same header-plus-body input, and prints 64-character ids. Nothing else about the rule changes, which is why both ids appear here. The two id spaces do not interoperate, so an id from a SHA-1 repository cannot be translated; a conversion means rewriting the objects.
Is SHA-1 a problem for these ids?
SHA-1 collisions have been constructed since 2017, and git's answer was to switch its internal hash to a hardened variant that detects the known attack pattern and refuses the input rather than to change every id. For any ordinary file the hardened function and plain SHA-1 agree, which is why the value here matches git's — the difference only shows on a crafted collision pair. Repositories that want a real margin use the SHA-256 object format.
Related tools
Hash Generator (SHA)
Generate SHA-1, SHA-256, SHA-384, and SHA-512 hashes from text.
Developer
File Hash (Checksum)
Compute SHA-1, SHA-256, and SHA-512 checksums of any file.
File
DNSSEC Calculator — DS Record & NSEC3 Hash
Turn a DNSKEY into the DS record your registrar wants — key tag and all three digest types — or hash a name the way NSEC3 does.
Network
File Hash Verifier
Drop a file and paste an expected SHA-1 / 256 / 384 / 512 — see if the actual hash matches. Useful before installing downloaded binaries.
File
CSP Hash Generator
Compute the sha256 / sha384 / sha512 base64 hash an inline <script> or <style> block needs to be whitelisted by a Content-Security-Policy.
Network
Conventional Commit Message Builder
Build a Conventional Commits message with type, scope, breaking change, and footers, in your browser.
Developer