Search notes:

git hash-object

Compute object ID (aka object name) and optionally creates a blob from a file.
A file's hash can be determined without being in a git repository.

Influence of the core.autocrlf option

The following commands demonstrate the influence of the core.autocrlf option on calculating a file's hash.
First a repository is initialized:
git init --quiet repo
cd               repo
Github repository about-git, path: /commands/hash-object/core.autocrlf/init.ps1
Two files are created, one with the traditional Unix end of line byte, 0x0A, named unix.txt, and another one, named dos.txt, with the traditional Windows end of line semantics, 0x0D 0x0A. I use the method WriteAllBytes of the .NET class System.IO.File in order to make sure that precisly those bytes get written I intend to.
[System.IO.File]::WriteAllBytes("$pwd/unix.txt", ([byte][char] 'f', [byte][char] 'o', [byte][char] 'o',       0x0a ))
[System.IO.File]::WriteAllBytes("$pwd/dos.txt" , ([byte][char] 'f', [byte][char] 'o', [byte][char] 'o', 0x0d, 0x0a ))
Github repository about-git, path: /commands/hash-object/core.autocrlf/create-files.ps1
The core.autocrlf is configured to false
git config  --local core.autocrlf false
Github repository about-git, path: /commands/hash-object/core.autocrlf/autocrlf.false.ps1
… and the files' hashes are calculated.
git hash-object unix.txt
git hash-object  dos.txt
Github repository about-git, path: /commands/hash-object/core.autocrlf/hash-objects.ps1
The command reports the hash of unix.txt to be 257cc5642cb1a054f08cc83f2d943e56fd3ebe99 and the hash of dos.txt to be e48b03ece74f47d1ae20075200c64aeaa01a9cdb. So, these files differ, as expected.
However, with setting core.autocrlf to true
git config  --local core.autocrlf true
Github repository about-git, path: /commands/hash-object/core.autocrlf/autocrlf.true.ps1
… both files will be reported to have the same hash: the hash of unix.txt.
git hash-object unix.txt
git hash-object  dos.txt
Github repository about-git, path: /commands/hash-object/core.autocrlf/hash-objects.ps1

See also

Git internals: hash-object
git commands

Index