0
0
Gitdevops~10 mins

Git mental model (snapshots not diffs) - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Git mental model (snapshots not diffs)
Start: Working Directory
Create Snapshot of Files
Store Snapshot as Commit
Link Commits in Chain
Checkout Commit to Restore Files
Modify Files -> New Snapshot
Repeat
Git saves the whole state of your files as snapshots in commits, not just changes. Each commit stores a full picture of your project at that time.
Execution Sample
Git
git add .
git commit -m "Save snapshot"
git checkout HEAD~1
Add all files, save a snapshot as a commit, then go back to the previous snapshot.
Process Table
StepActionFiles StateCommit CreatedCommit Chain
1Start with files in working directoryFiles A, B, C (current content)NoNo commits yet
2git add .Files staged for commitNoNo commits yet
3git commit -m "Save snapshot"Files saved as snapshotCommit 1 createdCommit 1 (root)
4Modify File BFile B changed in working directoryNoCommit 1
5git add .Files staged for commitNoCommit 1
6git commit -m "Save snapshot 2"Files saved as snapshotCommit 2 createdCommit 1 -> Commit 2
7git checkout HEAD~1Files restored to Commit 1 stateNoCommit 1 -> Commit 2 (HEAD detached)
8EndFiles at Commit 1 snapshotNoCommit 1 -> Commit 2 (HEAD detached)
💡 Checked out previous commit snapshot, HEAD detached at Commit 1
Status Tracker
VariableStartAfter Step 3After Step 6After Step 7
Working Directory FilesA,B,C originalA,B,C snapshot 1A,B modified,C snapshot 2A,B,C snapshot 1 restored
Commit ChainNoneCommit 1Commit 1 -> Commit 2Commit 1 -> Commit 2 (HEAD detached)
HEAD PointerNoneCommit 1Commit 2Commit 1 (detached)
Key Moments - 3 Insights
Why does Git store snapshots of all files instead of just the changes?
Git saves the full state of files at each commit (see execution_table steps 3 and 6). This makes it faster and simpler to restore any commit without calculating changes.
What happens to the files when you checkout an older commit?
The working directory files are replaced by the snapshot from that commit (see execution_table step 7). This is why files look like they reverted to an earlier state.
Is the commit chain lost when you checkout an older commit?
No, the commit chain remains intact (see variable_tracker Commit Chain after step 7). HEAD just points to an older commit temporarily (detached HEAD).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table at step 3. What does Git do at this step?
AModifies files in the working directory
BChecks out the previous commit
CCreates the first commit snapshot of all files
DDeletes all files
💡 Hint
Check the 'Commit Created' and 'Files State' columns at step 3
At which step does the working directory files get restored to an earlier snapshot?
AStep 7
BStep 6
CStep 4
DStep 2
💡 Hint
Look for 'Files restored to Commit 1 state' in the 'Files State' column
If you modify files but do not commit, what happens to the commit chain?
AIt adds a new commit automatically
BIt stays the same
CIt deletes the last commit
DIt resets to the first commit
💡 Hint
See variable_tracker 'Commit Chain' after step 4 where files are modified but no commit is made
Concept Snapshot
Git saves full snapshots of your files at each commit.
Each commit stores the entire project state, not just changes.
You can restore any commit by checking it out.
HEAD points to the current commit.
Modifying files doesn't change commits until you commit.
This model makes history simple and fast to navigate.
Full Transcript
Git works by saving snapshots of your entire project files at each commit, not just the differences. When you add and commit, Git takes a picture of all your files as they are. This snapshot is stored as a commit and linked in a chain with previous commits. When you checkout a commit, Git replaces your working files with the snapshot from that commit, letting you go back in time. Modifying files alone does not affect commits until you stage and commit again. This snapshot model helps Git be fast and reliable in managing your project history.