Skip to content

Instantly share code, notes, and snippets.

@CamiloGarciaLaRotta
Last active February 18, 2021 14:43
Show Gist options
  • Save CamiloGarciaLaRotta/18192d57ba6e69b06823a06f8898bb4a to your computer and use it in GitHub Desktop.
Save CamiloGarciaLaRotta/18192d57ba6e69b06823a06f8898bb4a to your computer and use it in GitHub Desktop.
Git under the hood

commit

Made of:

  • a tree: PWD state, not a diff, but rather an efficient representation of the full state
  • a comment
  • commiter info
  • hash of parent commit Process:
  • if file didn't change: add compressed filename (hash) to the snapshot
  • if file changed: compress it, store it in .git/objects, add filename hash to snapshot

.git/objects

Q. What is an object? A. a commit, tree, blob

git cat-file -p

pretty print a git object

$ git cat-file -p <tree-hash>
obj-type-code+perms obj-type obj-hash <filename> 
100644              blob     <hash>   world.txt

blobs

stored as the deflated: blob <blob-length><null-char><blob>

trees

stored as the deflated: tree <tree-length><null-char>FOREACH object<mode> <filename><object id in hex>

commits

stored as the deflated:

commit <commit-length><null-char>tree <tree-hash>\
author <author-name> <author-email> <timestamp>\
commiter <commiter-name> <commiter-email> <timestamp>\

<commit-msg>

ids or hashes

SHA1 of <obj-type> <obj-size><null-char><obj>

@CamiloGarciaLaRotta
Copy link
Author

foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment