mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Determine The Hash Id For A Blob as a git til.
This commit is contained in:
16
git/determine-the-hash-id-for-a-blob.md
Normal file
16
git/determine-the-hash-id-for-a-blob.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Determine The Hash Id For A Blob
|
||||
|
||||
Git's `hash-object` command can be used to determine what hash id will be
|
||||
used by git when creating a blob in its internal file system.
|
||||
|
||||
```bash
|
||||
$ echo 'Hello, world!' > hello-world
|
||||
$ git hash-object hola
|
||||
af5626b4a114abcb82d63db7c8082c3c4756e51b
|
||||
```
|
||||
|
||||
When a commit happens, git will generate this digest (hash id) based on the
|
||||
contents of the file. The name and location of the file don't matter, just
|
||||
the contents. This is the magic of git. Anytime git needs to store a blob,
|
||||
it can quickly match against the hash id in order to avoid storing duplicate
|
||||
blobs.
|
||||
Reference in New Issue
Block a user