Git From Bottom Up - part 1 - repo
Mostly a summary
Blobs
Git maintains snapshots of our directory’s content. File’s contents are represented in blobs. The blob is named with SHA1 hash id of its size and contents. Blobs content never change, meaning we can use this blob for representing the same content “everywhere” - across commits, repos, across the internet. Blobs don’t actually hold metadata about its content, this information is kept in the tree which holds our blob.
Running these commands
1$ mkdir test-git
2$ git init
3$ echo 'blob-test' > testing
4$ git add testing
5$ git commit -m "commit message"
will generate the same blob hash id “globally”, can check with
1$ git hash-object testing # get hash id from our file
2$ git cat-file -t e1a0b540dc61b7d68ee51b26ca5cce39aa76dd1c # get type of hash id
3blob
4$ git cat-file blob e1a0b540dc61b7d68ee51b26ca5cce39aa76dd1c # show content of file
5blob-test
Blobs and trees
Trees allows us to have a structure and naming of files. git ls-tree
can show
content of a tree object. In git, a head is the ref which points to the latest
commit of a branch. git cat-file commit HEAD
will show info about our last
commit, including which tree it belongs to.
1$ git ls-tree HEAD # show which tree of our HEAD
2100644 blob e1a0b540dc61b7d68ee51b26ca5cce39aa76dd1c testing
3$ git cat-file commit HEAD # show which tree our last commit is
4tree 685e97bfe5489d3ad8de413e0b0f01041f6a8e17
5$ git ls-tree 685e97bfe5489d3ad8de413e0b0f01041f6a8e17 # Show content of tree
6100644 blob e1a0b540dc61b7d68ee51b26ca5cce39aa76dd1c testing
Making of trees
A tree can be created manually with git write-tree
- the tree is created from
the current index.