Skip to content

File States and Areas

Git needs to distinguish work you are still editing from content you have selected for the next commit and content already recorded. Treating all three as one “saved file” leads to accidental commits and missing changes.

Working Tree → files you open and edit
Staging Area/Index → content selected for the next commit
Local Repository → content and history already recorded by Git

Saving a file in an editor updates the Working Tree. It does not automatically update the Staging Area or create a commit. Staging selects the file content as it exists at that moment; a later edit can therefore leave a different version in the Working Tree.

The Staging Area is not just a compulsory stop. It lets you assemble a coherent next commit from selected changes while other work remains unfinished. Git stores the index internally; edit it through Git commands, not by changing .git/index by hand.

State Meaning
untracked A new file exists in the Working Tree, but Git has not begun tracking it.
tracked Git knows the file from staging or recorded history.
unmodified Tracked content matches the recorded version.
modified A tracked file has a Working Tree change.
staged Specific content has been selected for the next commit.

These terms answer different questions. “Tracked” is not the opposite of “modified”: a tracked file can be modified. Likewise, a path can have staged content and a newer unstaged edit at the same time.

Suppose ex.txt is created with its first line and then staged. The staged version is the first content. If you edit ex.txt again without staging it again, the newer content exists only in the Working Tree:

Staging Area → ex.txt, version 1
Working Tree → ex.txt, version 2

A commit made now records the staged version 1. Version 2 remains in the Working Tree. The commit does not silently pick up the latest editor contents.

In a disposable exercise, Git reported ex.txt both as new file under changes to be committed and as modified under changes not staged for commit. This was one path with two different content states, not two separate files. The detailed format of git status is covered in the next checkpoint.

During a Laravel change, you may finish a test but still be experimenting with an unrelated configuration file. Stage the completed test only; the other edit can remain in the Working Tree. That gives the next commit a focused purpose.

Avoid these assumptions:

  • “I pressed Save, so Git will include the file in my next commit.” Editor saves only update the Working Tree.
  • “I staged the filename, so all later edits to it are staged too.” Staging selects the content at that time.
  • “A tracked file must be unmodified.” Tracked files can be modified or staged.
  • “The staging area has no purpose beyond making Git accept a commit.” It allows deliberate selection of the next recorded content.
new file → untracked
tracked, unchanged → unmodified
tracked, edited → modified in Working Tree
selected current content → staged
edited after staging → staged older version + unstaged newer version
Does saving a file in an editor stage it?

No. It updates the Working Tree only.

Which version enters a commit after a file is edited again without restaging?

The earlier staged version. The newer Working Tree edit remains unstaged.

Can a tracked file be modified?

Yes. “Tracked” means Git knows the path; “modified” describes its changed content.