Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 127 additions & 1 deletion book/10-git-internals/sections/plumbing-porcelain.asc
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,131 @@ The `hooks` directory contains your client- or server-side hook scripts, which a

This leaves four important entries: the `HEAD` and (yet to be created) `index` files, and the `objects` and `refs` directories.
These are the core parts of Git.
The `objects` directory stores all the content for your database, the `refs` directory stores pointers into commit objects in that data (branches, tags, remotes and more), the `HEAD` file points to the branch you currently have checked out, and the `index` file is where Git stores your staging area information.
The `objects` directory stores all the content for your database, the `refs` directory stores pointers into commit objects in that data (branches, tags, remotes and more), the `HEAD` file points to the branch you currently have checked out, and the `index` file is where Git stores your staging area information
You'll now look at each of these sections in detail to see how Git operates.

=== Understanding the Initial State of a Git Repository

When a new repository is initialized using `git init`, Git creates the `.git` directory to maintain repository metadata and version history.

In our experiment, the repository was initialized using:

[source,console]
----
$ git init -b main
----

The initial repository contains the following important components:

[cols="1,2"]
|===
|Component |Purpose

|`HEAD`
|Identifies the currently checked-out branch.

|`objects/`
|Stores Git objects such as blobs, trees and commits.

|`refs/`
|Stores references to commits, including branch and tag references.

|`config`
|Stores repository-specific configuration.

|`index`
|Stores the staging area information. It is created when files are staged.
|===

In our experiment, `HEAD` refers symbolically to `refs/heads/main`. Since no commit exists initially, the main branch is an unborn branch and does not yet point to a commit.

=== Understanding the Working Tree, Index and Repository

Git maintains three important areas when tracking changes:

. Working Tree: Contains the actual files being edited.
. Index: Contains the changes prepared for the next commit.
. Repository: Stores committed snapshots and their history.

The following diagram represents this relationship:

[source,text]
----
+------------------+
| Working Tree |
| |
| notes.txt |
| alpha |
+------------------+
|
| git add
v
+------------------+
| Index |
| |
| Staged changes |
+------------------+
|
| git commit
v
+------------------+
| Repository |
| |
| Commit objects |
| Tree objects |
| Blob objects |
+------------------+
----

=== Understanding HEAD and Branch References

A branch in Git is a reference that points to a commit. HEAD identifies the currently checked-out branch.

In our experiment, three commits were created:

[source,text]
----
Commit A
|
v
Commit B
|
v
Commit C
----

The `topic` branch was created while the repository was at Commit B. Commit C was then created on the `main` branch.

The resulting branch structure is:

[source,text]
----
main
|
v
[Commit C]
|
v
topic ---> [Commit B]
|
v
[Commit A]
----

The `main` branch points to Commit C, while `topic` points to Commit B.

HEAD points symbolically to `main`, which currently identifies Commit C.

=== Understanding Git Objects

Git stores repository data using three important object types:

* Blob: Stores file contents.
* Tree: Stores directory structure and references to blobs or other trees.
* Commit: Stores a snapshot reference, parent commit information, author information and commit message.

Each object is identified by its content-based hash.

In our experiment, Git creates objects to represent the contents of `notes.txt`, `todo.txt`, directory snapshots and the three commits.

This object-based structure allows Git to maintain historical snapshots and relationships between commits.
40 changes: 40 additions & 0 deletions work/R31-T042/actual/actual-results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"initial_state": {
"head": "ref: refs/heads/main",
"objects_exists": true,
"refs_exists": true,
"index_exists": false,
"main_branch_exists": false,
"working_tree_status": ""
},
"commit_ids": {
"A": "edae18d32d1fff2ffff02346738151ce5799b4e6",
"B": "73d5e3f3a729f4b2073230024eb2bfbb54535dd2",
"C": "55295b8e6f5dd567c2e3667966d0632bd1717c17"
},
"commit_parents": {
"A": [],
"B": [
"edae18d32d1fff2ffff02346738151ce5799b4e6"
],
"C": [
"73d5e3f3a729f4b2073230024eb2bfbb54535dd2"
]
},
"branches": {
"main": "55295b8e6f5dd567c2e3667966d0632bd1717c17",
"topic": "73d5e3f3a729f4b2073230024eb2bfbb54535dd2"
},
"current_branch": "main",
"commit_count": 3,
"tracked_files": [
"notes.txt",
"todo.txt"
],
"final_working_tree_status": "",
"authors": {
"A": "Course Student\tstudent@example.invalid",
"B": "Course Student\tstudent@example.invalid",
"C": "Course Student\tstudent@example.invalid"
}
}
7 changes: 7 additions & 0 deletions work/R31-T042/actual/test-summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tests_run": 8,
"tests_passed": 8,
"failures": 0,
"errors": 0,
"successful": true
}
3 changes: 3 additions & 0 deletions work/R31-T042/actual/tool-versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Python: 3.15.2
Platform: macOS-27.2.1-arm64-arm-64bit-Mach-O
git version 2.54.0 (Apple Git-157)
Loading