Git Foundations / Record Your Work

How Git records work

Lesson 4 of 33. Open to read. No account needed.

Snapshots, Not Copies

Saving a copy of a file called report-v2 records the new contents, but not what changed, who changed it or why, and not which other files changed at the same time. Git records something richer. Each commit is a snapshot of every file Git is tracking in the project, taken at one moment, together with:

  • the author's name and email (the settings from the previous lesson);
  • the date and time;
  • a message describing the change;
  • a link to the commit that came before it, called its parent.

Because every commit points to its parent, the commits form a chain: the project's history. Following the chain backwards takes you through every recorded state of the project.

A snapshot does not mean Git stores every file again. Content that has not changed since an earlier commit is reused, so recording a change to one file in a large project stays small.

Git identifies each commit by a long string of letters and digits, called the commit ID, calculated from the commit's contents. Git usually shows only the first several characters, such as 13a88ef. Each commit gets its own ID, and changing anything in a commit would produce a different ID. The IDs in this course are illustrative: yours will differ.

Three Places a Change Passes Through

A change moves from the working tree, where you edit files, to the staging area with git add, and from the staging area into the repository with git commit. The repository holds commits 1, 2 and 3; each points back to its parent, and the branch name main labels the newest commit.

Git works with three places, shown from top to bottom in the diagram:

  1. The working tree is the set of files you see in the project folder and edit with your usual tools. Git does not record anything just because you edited a file.
  2. The staging area, also called the index, holds the snapshot you are preparing for the next commit. git add copies a file's current contents from the working tree into it.
  3. The repository holds the commits. It lives in a hidden folder called .git at the top of the project. git commit records the staging area as a new commit, whose parent is the previous commit.

At the bottom of the diagram, main is the branch name from the previous lesson. It labels the newest commit and moves forward each time you commit. Branches get their own module later.

The staging area is what lets you choose what goes into a commit. If you edited three files but only two belong to one change, you stage those two and commit them, leaving the third for a separate commit. The next lessons rely on this.

Following One File Through

Here is one file, todo.txt, followed through two commits. Each row shows what each place holds after the step, and what git status, the command that compares the three places, reports. In the table, "milk" stands for the version of the file containing only "Buy milk", and "milk, bread" for the version with both lines.

StepWorking treeStaging areaRepositorygit status reports
1. Create todo.txt containing "Buy milk"milkNothing for this fileNo commitsUntracked file
2. git add todo.txtmilkmilkNo commitsChange to be committed
3. git commitmilkmilkCommit 1: milkNothing to commit
4. Add a line, "Buy bread"milk, breadmilkCommit 1: milkChange not staged
5. git add todo.txtmilk, breadmilk, breadCommit 1: milkChange to be committed
6. git commitmilk, breadmilk, breadCommit 2 (parent: 1)Nothing to commit

Two details in this table catch people out.

After step 3, the staging area is not empty. It still holds the snapshot that was just committed, and becomes the starting point for the next one. git status shows nothing to commit because the three places agree, not because the staging area is empty.

In step 4, the edit exists only in the working tree. Running git commit at that moment creates no commit at all: Git reports no changes added to commit, because the staging area still matches commit 1. Only what is staged gets committed.

Reading git status

git status reports the differences between the three places, in these groups:

GroupMeaning
Untracked filesFiles in the working tree that Git has never been asked to track
Changes not staged for commitThe working tree differs from the staging area
Changes to be committedThe staging area differs from the last commit
Nothing to commit, working tree cleanAll three places agree

One file can appear in two groups at once. That happens when you stage a version and then edit the file again: the staged version differs from the last commit, and your newer edit differs from the staged version.

Common Misconceptions

  • "Committing saves my files." It records the staging area. Edits you have not staged stay out of the commit.
  • "The staging area empties after each commit." It holds the complete next snapshot; git status only shows how it differs.
  • "Each commit stores a full copy of every file." Unchanged content is reused between commits.
  • "The .git folder is just settings." It holds the whole history. Deleting it deletes every commit.

Check Your Understanding

You create a new file, todo.txt, containing "Buy milk", and run git add todo.txt. Before committing, you add a second line, "Buy bread".

  1. Predict what git status shows for todo.txt.
  2. If you run git commit now, which version of the file does the commit record?
  3. What would you do to include both lines in the commit?

Answer and Reasoning

  1. todo.txt appears twice: under "Changes to be committed" as a new file, because the staged version is not in any commit yet, and under "Changes not staged for commit" as modified, because the working tree now differs from the staged version.
  2. Only "Buy milk". The commit records the staging area, which still holds the version from when you ran git add.
  3. Run git add todo.txt again before committing. That copies the current version, with both lines, into the staging area.

You can check these predictions yourself after the next lesson, which creates a real repository.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy