Git & GitHub Interview Question #119
What is the difference between a blob, tree, and commit object in Git?
Advanced GitHub Actions, Repository Internals, Submodules, LFS & Diagnostic Tools Senior Advanced
Quick Interview Answer
A blob stores file content without a filename. A tree maps names to blobs or other trees and therefore represents a directory snapshot. A commit points to a root tree and records metadata such as parent commit references, author information, committer information, and a message.
Detailed Explanation
A blob stores file content without a filename. A tree maps names to blobs or other trees and therefore represents a directory snapshot. A commit points to a root tree and records metadata such as parent commit references, author information, committer information, and a message.
Together these objects represent the project snapshot and its relationship to history.
Code Example
git cat-file -p HEAD
# Show the root tree referenced by HEAD
git ls-tree HEAD