Lesson 1.2. Three File States and Three Areas

One commit — and var_dump() in production

You spent an hour hunting a bug. Fixed it — and along the way left a var_dump($order), a temporary hack and a commented-out chunk "just in case" in the code. You type git commit -am "Fix checkout" — and all of it flies into the repository together, and from there to the site.

Git lets you avoid this. Between "changed a file" and "saved it in history" there's an intermediate area where you decide exactly what goes into the commit: the fix — yes, var_dump — no.

Those who understand these three areas make clean commits and aren't afraid of git status. Those who don't keep asking: "Why didn't my changes get committed?" and "Where did this come from?"

Goal

Understand which states a file goes through from a change to a commit.

Key concepts

flowchart LR
  WD["✎ Working directory<br/>the files you work with<br/>**untracked · modified**"]
  SA["▣ Staging area (index)<br/>what goes into the next commit<br/>**staged**"]
  RP[("◉ Repository .git<br/>saved commits<br/>**committed**")]

  WD -->|"git add"| SA
  SA -->|"git commit"| RP
  SA -.->|"git restore --staged"| WD
  RP -.->|"git restore / checkout"| WD

  classDef work fill:#fff7ed,stroke:#f97316,color:#7c2d12
  classDef stage fill:#f5f7ff,stroke:#4f46e5,color:#1e1b4b
  classDef repo fill:#ecfdf5,stroke:#10b981,color:#065f46
  class WD work
  class SA stage
  class RP repo

Commands / artifacts

BASH
git status
git add file.php
git commit -m "Add file"

Common mistakes

SymptomCauseFix
Changes didn't make it into the committhe file wasn't added to staginggit add before git commit

Practice

Create a file, change it, and run git status after each step.

git — Module 1. Git Basics

Interview Questions

To build the next commit deliberately: add only part of your changes (even part of a file with git add -p) and leave the rest for later. That keeps commits small and logical.

Untracked — Git doesn't track the file yet. A tracked file can be unmodified (matches the last commit), modified (changed but not added) or staged (added to the staging area). After git commit, staged changes go into the repository and the file is unmodified again.

Save your progress

Sign in or create a free account to mark lessons as completed and continue the whole course. You will come back to this lesson.