Home Work Week One : Advanced GIT
The goal of this class is to understand and learn more about git. The concept, how it works, and the flow. For that, the course will use the command line to understand git better and not through application/wizard, since it created to spare you the trouble.
git is distributed version control system
OTHER OPTIMIZATIONS - PACKFILES, DELTAS
- Git objects are compressed
- As files change, their contents remain mostly similar.
- Git optimizes for this by compressing these files together, into a Packfile
- The Packfile stores the object, and “deltas”, or the differences between one version of the file and the next.
- Packfiles are generated when: you have too many objects, during gc, or during a push to a remote
Git stores the compressed data in a blob, along with meta data in the header. Git store its data in git directory which contains data about our repository, and the blobs are stored in git objects. In git object, the blob missing some information (filename, directory structures) which is stored in a tree. A tree contain pointers to blobs and other trees because directory can be nested.
How Git stores information comparing it to a key-value store where data is the value and the hash of the data is the key. This system is also known as content-addressable storage, which is when the content to generate the key.
- you can then use the key to retrieve the content
- the key it's called a SHA1, is cryptographic hash function given a piece of data.
- it produces a 40-digit hexadecimal number and this value should always be the same if the given input is the same
- cant change this commit
- cant edit
- cant go back
- cant change the author
- cant change the date
- Tree
- Blob
- Commit
here for exercice to know more about what we are talking about
% tree .git/objects
.git/objects
├── 58
│ └── 1caa0fe56cf01dc028cc0b089d364993e046b6
├── 98
│ └── 0a0d5f19a64b4b30a87d4206aade58726b60e3
├── 99
│ └── b2172e47a9367ff4cb3fc9c093090087688807
├── info
└── pack
- the Tree
% git cat-file -t 581ca
tree
% git cat-file -p 581ca
100644 blob 980a0d5f19a64b4b30a87d4206aade58726b60e3 hello.txt
- the Blob
% git cat-file -t 980a0
blob
% git cat-file -p 980a0
Hello World!
- the Commit
% git cat-file -t 99b21
commit
% git cat-file -p 99b21
tree 581caa0fe56cf01dc028cc0b089d364993e046b6
author Rezha Erlangga <reza@machtwatch.co.id> 1642390839 +0700
committer Rezha Erlangga <reza@machtwatch.co.id> 1642390839 +0700
Initial commit
Three areas where code lives : working area (or sometimes called as working tree), staging area (or cache or index) and repository. The working area are the files in your working area that are not in staging area and not handled by git, basically the files in your local directory in your computer. The staging area is how git knows what will change between the current commit and the next commit. The repository contains all your commits. Git stash is used to save un-committed work and safe from git destructive operation like changing branches while in the middle of work or overwriting file. And you can apply it back to your branch anytime when needed.
git stash
git stash list
git stash list
git stash show stash@{n}
git stash apply
git stash apply stash@{n}
git stash --include-untracked
git stash --all
git stash pop
git stash drop
git stash drop stash@{n}
git stash clear
Advanced GIT Nina Zakharenko here