#git-objects-four-types
The four object types in Git. What does each one store and how are they connected?
Что отвечать
A `blob` is the content of a single file, with no name and no permissions. A `tree` is the list of entries for one directory: permissions, type, SHA, name. A tree entry points either at a blob (a file) or at another tree (a subdirectory), which gives you a recursive tree. A `commit` is the SHA of the root tree plus metadata: parent(s), author, committer, date, message. A `tag` is a named pointer to a commit, usually with a signature.
Что хотят услышать
A senior should: - call Git a key-value store: the key is the SHA, the value is the zlib-compressed object in `.git/objects/` - explain the tree recursion: a directory tree is a tree of tree objects - say that a blob does not know the file name. The name lives in the tree that points at the blob - explain why a branch is just a file with one SHA in `.git/refs/heads/<name>`, and HEAD is a file with a pointer to a branch - distinguish an annotated tag (an object in `.git/objects/`) from a lightweight tag (just an entry in `.git/refs/tags/`)
Подводные камни
- ✗ Saying "a commit stores changes". In reality a commit stores a full snapshot through a tree, and Git computes the diff on the fly
- ✗ Saying "a blob knows the file name". It does not. The name is added by the tree object
- ✗ Confusing a tag object with a branch. Both are refs, but a tag usually does not move while a branch does
Follow-up
- ? What does `git cat-file -p HEAD^{tree}` show?
- ? Where does the branch `feature/x` physically live?
- ? How does a lightweight tag differ from an annotated one in terms of objects?
Глубина в базе знаний