Join us
GIT — is a powerful tool for collaborating with the team and storing work that can be easily replayed in time. However, for a sad reason, a lot of people use the GUI tool for interacting with it and can’t uncover its full potential of this tool. Like in a famous meme people learn only to commit and push and if something happened, they prefer to reload copies except to solve problems. (In all cases it’s not the optimal way)
Requirements
Why use the command line?
All GUI tools for git have been built on top of CLI, also nowadays they’ve become very rich, but they lack functionality from the original CLI. For simple tasks it’s not a big deal, but for complicated one missing functionality start to become vital.
GUI can sometimes create a layer of abstraction for the user, that becomes only available only in this proprietary tool putting boundaries on choosing software freely.
Last, but not least CLI commands can be automatized using bash on your demand. (Combining several commands you can gain a stunning result) With GUI — you’re fully dependent on vendor updates.
What is GIT?
GIT — Distributed Version Control System
Let’s unpack this. Distributed — means that storing of data is the responsibility of several computers, not a single one. For example, the server, our computer and collaborator Bob’s computer. Distributing doesn’t mean that our data will be synchronized.
Version Control System — every object (in our case file) have an established state in time (version) and we can manage this state and go back and forward replaying it. (control system).
How does GIT store information?
The key — SHA1
The value — BLOB
GIT stores the compressed data in a blob, along with metadata in a header:
\0
delimiter
This picture can be misleading, so you should understand that these four blocks are sequentially and do not lie on a disk as presented in the mnemonic picture.
Under the hood — GIT Hash-Object
Let’s ask git for SHA1 of content
Result
Let’s try with metadata
Result
It’s a match with the previous result
Where does GIT store its data?
.git
the directory contains info about the repository
We need more info
The block lacks information:
Git manages this information in a tree.
Tree
A tree contains pointers (using SHA1):
and metadata:
Other optimizations — Packfiles and deltas
git commit
), or during a push to a remoteCommits
Commit object
commit points to a tree
and contains metadata:
the SHA1 of the commit is the hash of all this information
A commit is a code snapshot
Commits under the hood — make a commit
Commits under the hood — look in .git objects
Commits under the hood — looking at objects
Oops, remember that content is compressed.
Git cat-file -t (type) and -p (print the contents)
Why we can’t change commits?
References — pointers to commit
References under the hood
refs/heads
are where branches live
we show only part of the tree command output in the example
/refs/heads/master
contains which commit the branch points to
HEAD is usually a pointer to the current branch
Join other developers and claim your FAUN account now!
Student
@d9nichInfluence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.