Skip to the workspace
Pebellslearn by building
Version Control with Git  ›  Lesson

Git — Saving Snapshots

Git 14 minGit records a project as a chain of commits, and each commit is a snapshot of whatever you staged, with a message saying why.

backend / Git — Saving Snapshots

Explore each scene at your own pace.

01 · The rule

The rule

Git — Saving Snapshots

You change the bookshop's order code on Friday, and on Monday checkout is broken. What exactly changed, and how do you get back to Friday morning? Without version control you are guessing. With Git, every saved step is a snapshot you can inspect, compare and return to.

The rule

Edit, stage, commit: each commit is a snapshot with a reason.

Git sees your project in three places:

  • Working directory: the files as they are on disk right now, including half-finished edits.
  • Staging area: the changes you have chosen for the next snapshot.
  • Repository: the permanent history of commits, stored in the hidden .git folder.

A commit records the staged state of the project, together with an author, a time, a message and a link to the commit before it. Each commit gets a unique id (a hash such as a1b2c3d), and together they form a chain you can walk back through.

git init                      # start tracking this folder
git status                    # what changed? what is staged?
git diff                      # show unstaged line changes
git add app.py                # stage one file
git commit -m "Return 404 for unknown book ids"
git log --oneline             # list the history, newest first

Staging exists so that one commit can hold one idea. If you fixed a bug and also reworded the README, stage and commit them separately; later, each change can be understood or undone on its own.

A good message says what changed and why in a short line: "Return 404 for unknown book ids" beats "fix stuff".

Some files must never be committed: secrets such as .env with the database password, and generated folders such as node_modules or __pycache__. List them in a .gitignore file:

.env
__pycache__/
node_modules/
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.