How does Git store data?
Git stores data not as a set of diffs, but as snapshots of the project state.
Key idea
Each commit is a full snapshot of all project files at the time of the commit. If a file has not changed, Git does not duplicate it, but simply references the already stored version.
What data in Git consists of
Git stores everything as objects:
- Blob - file content
Stores only the file's data, without a name or path.
- Tree - directory structure
Links file and folder names to blobs and other trees.
- Commit - a snapshot of the project
Contains:
- a reference to a tree (state of the files),
- reference(s) to parent commits,
- author, date, message.
- Tag - a named reference
Usually points to a specific commit (for example, a release).
How Git saves space
- unchanged files are not copied;
- hashing (SHA-1 / SHA-256) is used;
- identical content -> the same object.
Why this matters
- fast operations (commit, checkout, branch);
- data integrity (any change changes the hash);
- branches are just pointers to commits, not copies of code.
Short version for an interview
Git stores data as a set of project snapshots, using objects (blob, tree, commit), rather than as diffs between versions.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.