How git works – Onion View – Content tracker

Files are untracked. Git doesn’t know what to do with them. To commit a file you need to put it in a staging area (whatever it is in staging area it will go in the next commit).

git add/git commit

A commit is compressed like a blob. If we git cat-file the commit we will see that a commit is a simple, short piece of text. Git generates the commit and stores it like a blob. The commit contains all the metadata about the commit (the name of the author, the committer, the date of the commit, the message).

Mariuss-MacBook-Air:cookbook mariusistudor$ git cat-file -p  5a464f88150a3d1c406da815c60e712099e7b4b6

tree be4d5bfce489a2591e7fed5c672f9e52cd695a43

author Marius Istudor <[email protected]> 1584872355 +0200

committer Marius Istudor <[email protected]> 1584872355 +0200

First commit

Plus, it contains the SHA1 of a tree (the way a blob is a file stored in Git, a tree is a directory stored in Git). The commit is pointing to the root directory of the project.

The blob is not a file, it is the content of a file. The file name and the permissions are not store in the blob, they are stored in the tree that points to the blob. If you have the same data, you will get the same hashes. For commit, it will be different, because it will have different content (author, date, etc).

Git tags

A tag is a label for the current state of the project. There are two types of tags in git: regular and annotated.

Annotated tags are created using the git tag command and contain metadata such as name of the tag, message, time and date and an object that the tag is pointing to. A tag can be simply considered as a simple label attached to an git object.

So, the Git object models contains:

blobs (arbitrary content)

trees (directories)

commits

annotated tags

Git can be considered like a high-level file system based on the native file system. Because it uses versioning (by commits) it is also considered a content tracker.

How git works – Onion View – Persistent structure

« Porcelain » commands

« Plumbing » commands – scripting

If you want to master git, you don’t need to worry about learning the commands. Instead, learn the concept model.

Git can be seen like an onion.

A simple persistent structure that maps keys to values (the structure is persistent, it’s stored on your disk) – the basic idea behind git: a map.

values = sequences of bytes (the content of a text value)

keys = git will calculate keys for these values using SHA1 (hash)

Every object (text files, directories, commits) in Git has its own SHA1. It is unlikely they will collide, they are unique.

Inside the .git directory, there is an object directory where Git saves all its objects.

git hash-object

git cat-file to see the content of the file (the original content was compressed to save space and added some more stuff).

Tooling helps improve codebase

What does quality of codebase mean?

  • Robustness
    Decent unit test coverage
    Good error handling
  • Maintainability
    simplicity
    Expressiveness (not obfuscated with large statements of ifs)
    Use of common idioms (
    Clean architecture
  • Ease of use
    Documentation (don’t rely on assumptions)
    Generic
  • Cost
    Development time overhead
    Technical debt
    Return on investment

Is quality worth the cost?

Quality cost is somehow easy to measure but the benefits are harder to evaluate.

  • automation and tooling can help reducing the cost
  • CPU time is cheaper than human time
  • it’s easier to replace hardware than hiring

Quality investment: Companies tend to view code as investment, regardless of its quality.