Explore the foundational structure of Git repositories with a focus on objects, trees, and blobs. This quiz helps users solidify their understanding of how Git manages data storage and relationships within its internals.
Which statement best describes a blob object in Git, especially when you add a new file to your repository?
Explanation: A blob in Git is designed to store the contents of a file as raw data, not including the filename or any directory structure. Option B is incorrect because the blob object itself doesn't record filenames or paths; tree objects do that instead. Option C is wrong since blobs are not aware of which trees reference them; only trees reference blobs, not the other way around. Option D is unrelated, as blobs are not used for storing branch metadata or commit information.
In Git, what is the primary role of a tree object within the repository structure?
Explanation: Tree objects in Git function to represent directories, connecting filenames to blob objects (for files) or other tree objects (for subdirectories). Option A is incorrect; blobs handle file content, not trees. Option B confuses tree objects with commits, which track parent commits. Option D is mistaken because change logging is handled elsewhere, not by tree objects.
How does Git uniquely identify each object, such as blobs and trees, in its repository storage?
Explanation: Git objects are uniquely identified by cryptographic hash values created with SHA-1 or, in newer setups, SHA-256. This ensures integrity and uniqueness regardless of file name or order. Option B is inaccurate because Git does not use sequential numeric IDs. Option C's method does not guarantee uniqueness or security. Option D is unrelated to how Git identifies or verifies objects.
When a commit is created in Git after staging changes, which elements does the commit object directly reference?
Explanation: A commit object in Git points to the preceding commit (parent), the current tree object (describing the repository's state), and contains the commit message as metadata. Option B is too limited, as commits do not directly point to individual files or blobs. Option C is wrong because branch names are managed separately and not within the commit object. Option D is incorrect; commits only point to the current state, not every blob in past history.
If the same file content is added to two different directories within a Git repository, how does Git store this data internally?
Explanation: Git is designed to avoid duplication by creating a single blob object for identical content, even when that content appears in multiple places. Trees will reference the same blob wherever needed. Option A is wrong because that would waste space. Option C is misleading since Git does not merge file contents unless explicitly instructed through a merge operation. Option D is incorrect because the blob itself does not store information about its directory location; that is handled by trees.