Object

Git is built around manipulating the structure of the 4 object types (blob, tree, commit, tag). In a way, it is like a mini-filesystem that sits upon the machine's filesystem

  • Nearly all git commands manipulate either the working tree, the staging area, or the commits.
  • objects are immutable
  • A git repo is a collection of objects, with each having its own hash
    • A commit is a hashed object
  • Each object consists of 3 things:
    • type - what type of object it is (blob, tree, commit, tag)
    • size - the size of the contents
    • content

SHA of Objects

Inside .git/objects, we see many hexadecimally named directories. The names of these are actually the first 2 digits of the SHA

  • ex. .git/objects/77/a54737 is the commit with SHA 77a54737...

The commits themselves are encrypted, but we can see the contents of the object with git cat-file -p <SHA>

  • use -t to see what type the object is

The below image is a representation of our workflow. Here we have 3 commits (with the first commit on the left). It's important to note how the same blob is referred by different trees. This is because that file didn't change between commits, therefore the blob is identical


Children
  1. Blob
  2. Commits
  3. Tag
  4. Tree