Git Behind the Scenes
Git is a version control system that tracks changes in files and folders by storing the project history internally.
Git Snapshots
- A snapshot represents the state of the code at a specific time
- Each snapshot is identified by a unique hash
- Git does not store differences, it stores snapshots
- Internally, Git stores data as objects in a key-value database
Git Objects (3 Musketeers)
1. Commit Object
- Represents a snapshot
- Stored inside the
.gitfolder -
Contains:
- Tree object reference
- Parent commit reference
- Author & committer
- Commit message
2. Tree Object
- Represents directories and file structure
-
Contains:
- File mode
- File name
- File hash
Everything is stored as key-value pairs in the tree object. The key is the file name and the value is the file hash.
3. Blob Object
- tree object and contains the actual file content
- Does not store file name or path