π¬ Peeling Back the Porcelain: Git as a Content-Addressable Filesystem
Most developers interact exclusively with Git's high-level user interfaceβknown in Git terminology as the Porcelain (commands such as git add, git commit, git branch, and git checkout). However, Git is fundamentally not a conventional monolithic revision control engine; it is an elegant, content-addressable key-value datastore with a Version Control System user interface built on top. Everything that defines your projectβevery file revision, every directory tree, every commit author, every branch pointer, and every tagβresides inside a single hidden directory at the root of your project: .git/. If you delete your entire working directory of source code but leave the .git folder intact, 100% of your codebase can be reconstructed in milliseconds. Conversely, deleting .git transforms your directory into an ordinary folder, severing its historical lineage. Understanding the structural layout of .git/ demystifies detached HEAD states, corrupt index recovery, garbage collection, and custom plumbing tool development.
.git repository root, mapping their storage formats, operational roles, and access lifecycles.
THE COMPLETE .git DIRECTORY TOPOGRAPHY:
.git/
βββ HEAD # Plaintext symbolic reference pointing to the currently active branch
βββ config # Local repository configuration file (overrides global ~/.gitconfig)
βββ description # Plaintext project summary used exclusively by the GitWeb daemon
βββ index # Binary directory cache (Tree 2: The Staging Area DIRC ledger)
βββ packed-refs # Optimized plaintext file packing thousands of historical branch/tag refs
βββ COMMIT_EDITMSG # Plaintext buffer holding the message of the most recent commit
βββ FETCH_HEAD # Tracking references recorded during the last 'git fetch' operation
βββ ORIG_HEAD # Backup reference to HEAD before dangerous operations (merge, reset)
β
βββ hooks/ # Client-side and server-side lifecycle hook shell scripts
β βββ pre-commit.sample # Executed before commit message generation (linting, secret checks)
β βββ prepare-commit-msg.sample
β βββ commit-msg.sample # Validates commit message structure (e.g. Conventional Commits)
β βββ post-commit.sample # Notification trigger after a commit is finalized
β βββ pre-rebase.sample # Guardrail script preventing rebasing of protected branches
β βββ pre-push.sample # Audits commits before transmission over network transport
β
βββ info/ # Auxiliary repository metadata
β βββ exclude # Private ignore patterns specific to this local clone (Untracked)
β
βββ logs/ # The Reflog ledger tracking every movement of HEAD and branch tips
β βββ HEAD # Chronological journal of every commit, checkout, merge, and reset
β βββ refs/
β βββ heads/ # Reflogs for local branches (e.g., logs/refs/heads/main)
β βββ remotes/ # Reflogs for remote tracking branches
β
βββ objects/ # The Content-Addressable Object Database (The Heart of Git)
β βββ [0-9a-f][0-9a-f]/ # Loose object directories partitioned by first 2 hex digits of SHA
β βββ info/ # Additional metadata regarding object packs
β βββ pack/ # High-efficiency compressed delta packfiles (.pack) and indexes (.idx)
β
βββ refs/ # Reference pointers mapping human names to 40-char SHA commit hashes
βββ heads/ # Local branch heads (e.g., refs/heads/main, refs/heads/feature-auth)
βββ remotes/ # Remote tracking branch heads (e.g., refs/remotes/origin/main)
βββ tags/ # Immutable tag references (e.g., refs/tags/v1.0.0)
HEAD file resolves branch pointers, and what occurs under a Detached HEAD state.
THE REFERENCE RESOLUTION CASCADE (DEREFERENCING HEAD):
Git references are simple files containing 40-byte hex hashes. The HEAD file determines
what commit is currently checked out in your working tree:
NORMAL BRANCH ATTACHMENT:
$ cat .git/HEAD
ref: refs/heads/main
HOW GIT RESOLVES YOUR CURRENT COMMIT:
1. Git opens '.git/HEAD' and reads: "ref: refs/heads/main" (A symbolic reference).
2. Git follows the path and opens '.git/refs/heads/main'.
3. Git reads the 40-character SHA-1 hash stored inside:
$ cat .git/refs/heads/main
3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea
4. Git queries the object database for commit object '3b4e3e53...'!
THE DETACHED HEAD STATE DEMYSTIFIED:
When you checkout an explicit commit hash, a remote tracking branch, or a tag directly:
$ git checkout 3b4e3e533604
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WHAT HAPPENS TO .git/HEAD UNDER A DETACHED HEAD STATE: β
β β’ Git replaces the symbolic pointer path with the LITERAL COMMIT HASH directly: β
β $ cat .git/HEAD β
β 3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea β
β β’ Operational Consequence: HEAD is no longer attached to any named branch ref! β
β β’ If you make commits in this state, they will NOT advance 'main' or any other branch pointer.β
β β’ If you switch branches without naming your work, the new commits become orphaned (dangling) β
β and will eventually be purged by Git's garbage collection (git gc)! β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
git pack-refs flattens references into an indexed packed-refs ledger.
THE PACKED-REFS OPTIMIZATION ARCHITECTURE:
PROBLEM: In large enterprise repositories with 10,000 tags and 5,000 active branches,
creating individual 41-byte files inside .git/refs/heads/ and .git/refs/tags/ exhausts
operating system directory inodes and severely slows down path traversal operations.
SOLUTION: git pack-refs
Periodically, Git flattens all loose references into a single, highly optimized, sorted
plaintext file located at '.git/packed-refs':
$ cat .git/packed-refs
# pack-refs with: peeled fully-peeled sorted
3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea refs/heads/main
a1b2c3d4e5f609871142bc481028841a9bc24d1e refs/heads/feature-auth
8841a9bc24d1e0f399a0f441209871142bc48102 refs/tags/v1.0.0
^c9941a2244114bc190a439f28d849201a22bc441
THE ANNOTATED TAG "PEELING" MECHANISM (THE CARET ^ NOTATION):
β’ Line 1: '8841a9bc...' is the SHA-1 of the ANNOTATED TAG OBJECT itself (containing the GPG signature,
tagger name, timestamp, and message).
β’ Line 2: '^c9941a22...' (prefixed with a caret ^) indicates the PEELED COMMIT OBJECT that the tag
actually points to!
β’ This enables Git to identify the target commit instantaneously without reading and decompressing
the annotated tag object from the object database!
LOOKUP PRECEDENCE LAW:
When Git searches for a ref (e.g. 'refs/heads/main'):
1. Git first checks if a loose file exists at '.git/refs/heads/main'. (Loose refs ALWAYS take precedence!).
2. If loose file is absent, Git searches the '.git/packed-refs' index file.
3. When you create or update a branch, Git writes a fresh loose file, overriding the packed entry!
.git/objects. Explains 2-character hexadecimal folder sharding, zlib deflate compression, immutable content addressing, and why Git shards objects across 256 subdirectories.
THE LOOSE OBJECT SHARDING ARCHITECTURE:
Every object in Git (Blobs, Trees, Commits, Tags) is identified by a 40-character hexadecimal
hash derived from its uncompressed payload (e.g., 3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea).
HOW GIT STORES OBJECTS ON THE FILESYSTEM:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Full Object Hash: 3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea β
β βββββ Remaining 38 characters: 4e3e533604c5a9f0d8c5708c5ae48b8846f7ea β
β βββ First 2 characters: "3b" β
β β
β Resulting Filesystem Path: β
β .git/objects/3b/4e3e533604c5a9f0d8c5708c5ae48b8846f7ea β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
WHY DOES GIT SHARD OBJECTS INTO 256 SUBDIRECTORIES (00 through ff)?
β’ Filesystem Inode Performance: Most operating system filesystems (ext4, NTFS, APFS) experience
severe directory lookup performance degradation when a single directory contains more than
10,000 individual files.
β’ Two-character hex sharding partitions the namespace across 16^2 = 256 discrete subfolders,
ensuring directory lookups remain fast even with 500,000 loose objects.
THE INTERNAL LOOSE OBJECT FILE FORMAT:
Every loose object file on disk is compressed using zlib Deflate.
Uncompressed payload format before zlib compression:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β [object_type_ascii] + [space: 0x20] + [size_bytes_ascii] + [null_byte: 0x00] + [raw_payload] β
β β
β Example Blob Storage: β
β "blob 19\0console.log('v1');" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
.pack archives and indexed via binary .idx files, reducing disk utilization by up to 90% while accelerating network transfers.
THE PACKFILE OPTIMIZATION ENGINE (.pack & .idx):
PROBLEM: Storing every single version of every file as an individual loose object on disk
wastes massive amounts of space (disk cluster slack space) and slows down network pushes.
SOLUTION: PACKFILES AND SLIDING-WINDOW DELTA COMPRESSION (git gc / git repack):
Git consolidates loose objects into two specialized companion files inside '.git/objects/pack/':
1. pack-[SHA].pack : The packed binary archive containing thousands of compressed objects.
2. pack-[SHA].idx : The high-speed binary index file providing instant O(log N) object lookups.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HOW GIT LOOKS UP AN OBJECT INSIDE A PACKFILE USING .idx VERSION 2: β
β β
β Target Hash: 3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea β
β β
β STEP 1: FIRST-LEVEL FAN-OUT TABLE (256 ENTRIES OF 4-BYTE INTEGERS) β
β β’ Reads index entry corresponding to first byte 0x3b. β
β β’ Provides the exact memory range offset where all hashes starting with 0x3b are stored. β
β β
β STEP 2: BINARY SEARCH ON SORTED SHA TABLE β
β β’ Executes binary search strictly within the 0x3b offset block to find matching 20-byte hash. β
β β’ Retrieves index position K. β
β β
β STEP 3: READ BYTE OFFSET TABLE & EXTRACT FROM .pack FILE β
β β’ Looks up Kth entry in the Offset Table to determine byte position inside the .pack file. β
β β’ Seeks directly to offset (e.g. Byte 884120) inside pack-[SHA].pack! β
β β’ Decompresses the object payload. If it is a delta, Git applies historical diffs in RAM. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
REVERSE DELTA COMPRESSION ADVANTAGE:
β’ Unlike legacy CVCS (which stores base version 1 and deltas forward), Git's packfile engine stores
the NEWEST (most recent) version of a file as a full object, and stores OLDER historical versions
as reverse deltas!
β’ Why? Because 99% of checkouts and reads access the latest version! The latest code is extracted
instantaneously without resolving delta reconstruction chains.
.git/logs/HEAD and .git/logs/refs/heads/, detailing the log entry format, expiration policies, and how to recover orphaned commits.
THE REFLOG RECORDING ARCHITECTURE (.git/logs/HEAD):
The Reflog is your local safety net. It records every single movement of the HEAD pointer
on your workstation (commits, checkouts, rebases, merges, hard resets, cherry-picks).
Reflog data is 100% LOCALβit is never transferred to remote servers during a push or pull!
INSPECTING THE RAW REFLOG FILE ON DISK:
$ cat .git/logs/HEAD
RAW ON-DISK REFLOG FILE FORMAT (TAB & SPACE DELIMITED):
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β [old_sha] [new_sha] [committer_name <email>] [unix_timestamp tz] [action_description] β
β β
β SAMPLE RAW ENTRIES: β
β 00000000 8841a9bc Aarav Sharma <aarav@nikita-infotech.com> 1793784000 +0530 commit (initial): init β
β 8841a9bc a1b2c3d4 Aarav Sharma <aarav@nikita-infotech.com> 1793784100 +0530 commit: add auth model β
β a1b2c3d4 3b4e3e53 Aarav Sharma <aarav@nikita-infotech.com> 1793784200 +0530 commit: add jwt route β
β 3b4e3e53 8841a9bc Aarav Sharma <aarav@nikita-infotech.com> 1793784300 +0530 reset: moving to HEAD~2 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
HOW THE REFLOG RESCUES CODE AFTER A DESTRUCTIVE 'git reset --hard':
1. Developer accidentally executes: $ git reset --hard HEAD~2
The commits 'a1b2c3d4' and '3b4e3e53' disappear from 'git log' and the branch history!
2. The developer panics, believing two days of work are permanently deleted.
3. IN REALITY: The commit objects STILL EXIST in '.git/objects/'! Only the branch pointer moved!
4. Developer inspects the reflog:
$ git reflog
Output: 8841a9b HEAD@{0}: reset: moving to HEAD~2
3b4e3e5 HEAD@{1}: commit: add jwt route <-- THERE IS OUR LOST WORK!
5. Developer restores the lost commit instantly:
$ git reset --hard HEAD@{1} (or git branch recovery-branch 3b4e3e5)
Result: Complete project history restored with zero data loss!
git fsck in graph verification, and how git gc --prune repacks objects and clears dead nodes.
THE GARBAGE COLLECTION & PRUNING LIFECYCLE:
WHAT IS A DANGLING / UNREACHABLE OBJECT?
An object residing in '.git/objects/' that cannot be reached by traversing parent links backward
from any active reference (branches, tags, remote tracking branches, or HEAD).
Dangling objects are created whenever you:
β’ Delete a branch before merging it.
β’ Run 'git reset --hard' to undo commits.
β’ Run 'git commit --amend' (the superseded original commit becomes dangling!).
β’ Run 'git rebase' (old commits are abandoned as new ones are forged).
DETECTING DANGLING OBJECTS VIA LOW-LEVEL PLUMBING (git fsck):
$ git fsck --unreachable --dangling
SAMPLE OUTPUT:
dangling commit 3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea
dangling blob a1b2c3d4e5f609871142bc481028841a9bc24d1e
HOW 'git gc' OPTIMIZES THE REPOSITORY:
When 'git gc' (Garbage Collection) executes:
1. Traverses the entire commit graph from all references in 'refs/' and 'HEAD'.
2. Gathers all reachable loose objects and writes them into a unified, delta-compressed packfile.
3. Checks reflog expiration timers (30-day grace period for unreachable objects).
4. If an unreachable object's modification time is older than the expiration window:
'git prune' permanently unlinks and deletes the dangling object from disk!
5. Compiles loose references into '.git/packed-refs'.
MANUAL EMERGENCY PURGE (REDUCING REPOSITORY SIZE IMMEDIATELY):
$ git reflog expire --expire=now --all
$ git gc --prune=now --aggressive
.git/HEAD, dereferences symbolic references, locates matching loose object files in .git/objects/, decompresses them via zlib, and parses the commit header and tree structure.
import os
import zlib
import re
from typing import Tuple, Dict, Any, Optional
class RawGitInternalsParser:
"""
Automated Low-Level .git Directory Parser:
1. Reads and dereferences .git/HEAD symbolic reference.
2. Traverses loose and packed references.
3. Decompresses raw zlib objects from .git/objects/ directly.
4. Parses commit headers, trees, authors, and commit messages.
"""
def __init__(self, repo_root: str = "."):
self.git_dir = os.path.join(os.path.abspath(repo_root), ".git")
if not os.path.exists(self.git_dir):
raise FileNotFoundError(f"Not a valid Git repository: {self.git_dir}")
def resolve_head(self) -> Tuple[str, str]:
"""Resolves HEAD to current branch name and target commit hash."""
head_path = os.path.join(self.git_dir, "HEAD")
with open(head_path, "r", encoding="utf-8") as f:
content = f.read().strip()
if content.startswith("ref:"):
ref_path = content.split(" ", 1)[1]
full_ref_path = os.path.join(self.git_dir, ref_path)
if os.path.exists(full_ref_path):
with open(full_ref_path, "r", encoding="utf-8") as rf:
commit_hash = rf.read().strip()
return ref_path, commit_hash
else:
# Fallback to .git/packed-refs if loose ref does not exist
commit_hash = self._resolve_packed_ref(ref_path)
return ref_path, commit_hash or "UNRESOLVED_PACKED"
else:
# Detached HEAD state: HEAD holds the raw commit hash directly!
return "DETACHED_HEAD", content
def _resolve_packed_ref(self, ref_name: str) -> Optional[str]:
packed_path = os.path.join(self.git_dir, "packed-refs")
if not os.path.exists(packed_path):
return None
with open(packed_path, "r", encoding="utf-8") as pf:
for line in pf:
line = line.strip()
if line and not line.startswith("#") and not line.startswith("^"):
parts = line.split(" ", 1)
if len(parts) == 2 and parts[1] == ref_name:
return parts[0]
return None
def read_loose_object(self, obj_hash: str) -> Tuple[str, bytes]:
"""Reads and decompresses an uncompressed loose object from .git/objects/."""
shard_dir = obj_hash[:2]
obj_filename = obj_hash[2:]
obj_path = os.path.join(self.git_dir, "objects", shard_dir, obj_filename)
if not os.path.exists(obj_path):
raise FileNotFoundError(f"Loose object not found on disk: {obj_path} (May be packed in .pack)")
with open(obj_path, "rb") as f:
compressed_data = f.read()
# Decompress zlib byte stream
decompressed = zlib.decompress(compressed_data)
# Split at null byte: header\0payload
null_idx = decompressed.find(b"\x00")
header = decompressed[:null_idx].decode("utf-8")
payload = decompressed[null_idx + 1:]
obj_type, size_str = header.split(" ")
return obj_type, payload
def parse_commit_payload(self, raw_payload: bytes) -> Dict[str, Any]:
text = raw_payload.decode("utf-8", errors="replace")
header_section, _, message = text.partition("\n\n")
headers = {}
for line in header_section.split("\n"):
if " " in line:
key, val = line.split(" ", 1)
headers[key] = val
return {
"tree": headers.get("tree"),
"parent": headers.get("parent"),
"author": headers.get("author"),
"committer": headers.get("committer"),
"message": message.strip()
}
if __name__ == "__main__":
print("==========================================================================")
print(" RAW .git DIRECTORY & OBJECT DATABASE PARSER")
print("==========================================================================")
# Simulated execution output for curriculum demonstration
print("[*] Inspecting Git repository internals at path: .git/")
print("[*] Reading .git/HEAD pointer...")
print(" βββ Status : Symbolic Reference (Attached to Branch)")
print(" βββ Target Ref : refs/heads/main")
print(" βββ Commit SHA : 3b4e3e533604c5a9f0d8c5708c5ae48b8846f7ea")
print("\n[*] Decompressing Loose Object from .git/objects/3b/4e3e533604... via zlib:")
print(" βββ Header Type : 'commit' (Payload Size: 242 Bytes)")
print(" βββ Tree Object : 8841a9bc24d1e0f399a0f441209871142bc48102")
print(" βββ Parent Commit: a1b2c3d4e5f609871142bc481028841a9bc24d1e")
print(" βββ Author : Aarav Sharma 1793784000 +0530")
print(" βββ Commit Msg : feat(auth): implement token revocation endpoint")
print("\n[β] Physical storage parsing successful. Object graph dereferenced.")
HEAD pointers, corrupt loose objects (zlib CRC errors), orphaned reference locks (index.lock), and verifying database integrity with git fsck.
REPOSITORY CORRUPTION SCENARIOS & RECOVERY PROTOCOLS:
// ==============================================================================
// PITFALL 1: "fatal: Unable to create '.git/index.lock': File exists"
// CAUSE: Git uses lockfiles (.git/index.lock, .git/refs/heads/main.lock) to guarantee
// atomic writes and prevent concurrent processes from corrupting repository state.
// If an IDE, terminal window, or background backup tool crashes during a Git operation,
// the stale lockfile is left orphaned on disk!
// REMEDIATION:
// 1. Ensure no other Git process is actively running:
// $ ps aux | grep git
// 2. Safely remove the orphaned lockfile manually:
// $ rm -f .git/index.lock
// ==============================================================================
// ==============================================================================
// PITFALL 2: "error: object file ... is empty / corrupt" (ZLIB INFLATE ERROR)
// CAUSE: Workstation sudden power loss during an active write: a loose object file was
// allocated on disk, but zero bytes were flushed, leaving a 0-byte corrupt file.
// REMEDIATION VIA REFLOG AND FSCK:
// 1. Identify the corrupt file path:
// $ git fsck --full
// Output: "error: object file .git/objects/3b/4e3e... is empty"
// 2. Remove the 0-byte corrupt loose file:
// $ rm .git/objects/3b/4e3e533604c5a9f0d8c5708c5ae48b8846f7ea
// 3. Inspect reflog to find the previous commit hash:
// $ git reflog
// 4. Restore the tree from the previous commit:
// $ git reset --hard HEAD@{1}
// ==============================================================================
// ==============================================================================
// PITFALL 3: "fatal: bad default revision 'HEAD'" (MISSING OR EMPTY HEAD)
// CAUSE: .git/HEAD was accidentally deleted or wiped to 0 bytes.
// REMEDIATION: Reconstruct the symbolic pointer manually:
// 1. Re-create the HEAD file pointing to your primary branch:
// $ echo "ref: refs/heads/main" > .git/HEAD
// 2. Verify with git status:
// $ git status
// Repository is immediately restored to working order!
// ==============================================================================
GIT INTERNALS SPECIFICATION MATRIX:
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β REPOSITORY COMPONENT β PHYSICAL PATH β STORAGE FORMAT β CORE OPERATIONAL ROLE β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Active Reference β .git/HEAD β Plaintext string β Symbolic pointer referencing β
β (HEAD Pointer) β β "ref: refs/..." β the active branch commit β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Content-Addressable β .git/objects/??/????... β zlib-compressed β Immutable database storing β
β Object Store β Sharded across 256 subfoldersβ Deflate stream β Blobs, Trees, Commits, Tags β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Packed Object Storage β .git/objects/pack/*.pack β Binary Delta β Compressed archive of loose β
β & Fan-out Index β .git/objects/pack/*.idx β Compressed Table β objects with binary search mapβ
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β The Staging Index β .git/index β Binary DIRC β Binary ledger tracking stat() β
β (The Cache) β β Structured Cache β cache and proposed commit β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Branch Pointers β .git/refs/heads/<branch> β Plaintext file β 41-byte movable pointer β
β (Local References) β β 40-char SHA hash β pointing to tip of branch β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Packed References β .git/packed-refs β Plaintext index β Consolidated ledger packing β
β (Optimized Refs) β β Sorted SHA lines β thousands of historical refs β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Reference Log β .git/logs/HEAD β Append-only text β Chronological audit journal ofβ
β (The Reflog) β .git/logs/refs/heads/ β Tab-delimited logβ every local pointer movement β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Lifecycle Hooks β .git/hooks/* β Executable shell β Pre-commit, commit-msg, and β
β (Automated Gating) β (e.g. pre-commit, pre-push) β / Python scripts β pre-push validation scripts β
βββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββ€
β TOP 5 GIT INTERNALS COMMANDMENTS: β
β 1. Git is Content-Addressable: Objects are indexed strictly by the cryptographic hash of their payload. β
β 2. Branches Are Just Files: A branch is literally a 41-byte plaintext file storing a 40-character SHA. β
β 3. Loose Objects Use zlib: Objects are compressed byte streams with an ASCII header and null byte. β
β 4. Reflogs Protect Against Accidents: Destructive operations like 'reset --hard' leave objects in logs. β
β 5. Lockfiles Prevent Race Conditions: Remove .git/index.lock only after confirming no active process. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ