From 45ea795502235f86d7494dc436df0f24e0e4d07a Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 10 Sep 2015 22:01:02 -0500 Subject: [PATCH] Add Determine The Hash Id For A Blob as a git til. --- README.md | 1 + git/determine-the-hash-id-for-a-blob.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 git/determine-the-hash-id-for-a-blob.md diff --git a/README.md b/README.md index d58958c..bca5ee7 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Checkout Previous Branch](git/checkout-previous-branch.md) - [Clean Out All Local Branches](git/clean-out-all-local-branches.md) - [Delete All Untracked Files](git/delete-all-untracked-files.md) +- [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md) - [Dry Runs in Git](git/dry-runs-in-git.md) - [Excluding Files Locally](git/excluding-files-locally.md) - [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md) diff --git a/git/determine-the-hash-id-for-a-blob.md b/git/determine-the-hash-id-for-a-blob.md new file mode 100644 index 0000000..a596553 --- /dev/null +++ b/git/determine-the-hash-id-for-a-blob.md @@ -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.