Up | Content | Intro | Concepts | Operations | Dictionary
Git is a system which follows the project folder history using snapshots. In Git the snapshots are also called commit objects. Each snapshot represents the project at the moment of the commit. The project itself is represented using trees objects for folders and blob objects for files. Each hash object has a unique 40 digits reference number.
A hash function is used to generate the 40 digit reference number. Hash functions have the special property to transform data sets of any size to data sets of a fixed size. In git the input data is the content of the object. A small change of the object's content will generate a big change in the output data. In the example below the value db79ba36b521373fcfaff3c2e422326a59fe26f6 is the identification code for the commit object.
$ git log -1
commit db79ba36b521373fcfaff3c2e422326a59fe26f6 (HEAD -> main, origin/main, origin/HEAD)
Author: Branimir Georgiev <-@->
Date: Sun Jan 9 20:05:15 2022 +0200
Git objects are binary files stored in .git/objects, whose names are generated using the hash function SHA-1. Git takes the first two digits to create a directory and the rest to create the object file.
$ tree /f ./git/objects
C:\WORKSPACE\TUTORIAL-GIT\.GIT\OBJECTS
│
├───db
│ 79ba36b521373fcfaff3c2e422326a59fe26f6
│
├───info
└───pack
Annotated tags contain a tag message and some additional information about the name of the tag, who created it, the date of the tagging and the object the tag refers to. The referenced object can be of any type, including other tags. Annotated tags are useful as snapshots for releases.
$ git cat-file -p mytag
object 3a7ed539ea18da12d5707001d7a4c176f8911240
type commit
tag mytag
tagger braboj <[email protected]> 1641911532 +0200
Commit objects store the metadata about a commit, such as the author, the date of the commit and references to the parent and all the other changes represented by a tree object.
$ git cat-file -p 3a7ed539ea18da12d5707001d7a4c176f8911240
tree da8d6f364612a07419ba0baf35dced6b52948c4f
parent 1f8716a405a8c09ef92012e713d3c087ae0b2678
author braboj <[email protected]> 1641905621 +0200
committer braboj <[email protected]> 1641905621 +0200
(TUT-GIT) - Add banners
A collection of references to either child trees or blob objects. Trees in git represent directories in the project folder.
$ git cat-file -p da8d6f364612a07419ba0baf35dced6b52948c4f
100644 blob b24d71e22373e5147f3c05c68a8742714a89b5d6 .gitignore
040000 tree 6e4aac2af494fac5de9b31ec3e522afc62b693b3 01-Introduction
040000 tree 34d3238ab9d7011ea10fd34ed90d0cc00ca1c5a6 02-Concepts
040000 tree 9ccf616a57c67dad449ebe9927006f001644ff5d 03-Operations
040000 tree 027b2a1a3ba3ce6ec61ac9438fb4760962d87919 04-Workflows
040000 tree d998eef3e1ecdfe68401e464ba19024360553830 05-Appendix
040000 tree b2c5547c1334a7462f3bb16f56868bf02ac6f12e Assets
100644 blob da746af85963471999b5ac8f6826a8bf841c1f7f CONTRIBUTING.md
100644 blob 4d4e68a8bdc24469d14f9bcff605396eb7de780c LICENSE.md
040000 tree 84232ef8e0c3532976caadf4ce719847f34cdc95 Playground
100644 blob 676b59c77fb333b04d30b1b66574f08af226d57f README.md
Binary large objects or BLOBS are compressed files and the end of the tree structure. They are the snapshots of a given file after a change has been added to the index.
$ git cat-file -p b24d71e22373e5147f3c05c68a8742714a89b5d6
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
# Show object content
$ git cat-file -p db79ba36b521373fcfaff3c2e422326a59fe26f6
# Show object type
$ git cat-file -t db79ba36b521373fcfaff3c2e422326a59fe26f6
- Create a git repo
- Check if the .git folder exists
- Create a new file
- Add the file to the index
- Check if a blob object was created
- Commit the file
- Check if a tree and commit objects were created
- Make a diagram of the object tree