Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Version Control with Git and GitHub  ›  Lesson

Git: Snapshots of Your Project

Git 12 minGit records a project's history as commits, and each change moves from the working folder to the staging area with git add and into history with git commit.

Git: Snapshots of Your Project

You tweak Sprout's plant list, it breaks, and you cannot remember what it looked like an hour ago. Git fixes that by keeping a history of snapshots you can inspect, compare and return to. It also becomes the way you share Sprout with anyone else.

The rule

Edit in the folder, choose with add, save with commit.

A change passes through three places:

Place What it holds Command that moves it on
Working folder Files as you are editing them git add
Staging area Changes chosen for the next snapshot git commit
History Saved snapshots (commits) —
git init                         # once: start tracking this folder
git status                       # what changed, what is staged
git add lib/plant_tile.dart      # stage one file
git commit -m "Show days left under each plant"
git log --oneline                # list the commits
  • A commit is a snapshot of every tracked file, plus a message, author and time. Each has an ID such as a1b2c3d.
  • flutter create gives you a sensible .gitignore, but it does not start a repository. Run git init yourself (many editors offer a button for it).
  • Write messages that say what the change does: "Show days left under each plant", not "stuff".

The shortcut

Before every commit, ask "Could I describe this in one short sentence?" If you need the word "and", split it.

Saving an afternoon of workStep 1 of 4
  1. Look

    git status shows two modified files: lib/plant_tile.dart and README.md.

Small, single-purpose commits pay off later: when the tile breaks, you can see or undo exactly that change without losing the README fix.

The trap is running git commit without adding first and wondering why nothing was saved. Only staged changes go into a commit.

Drills

Answer fast — trust the rule.

quick drill

Which command moves a changed file into the staging area?

quick drill

You edited a file but ran only git commit -m "Update". What happens?

quick drill

After flutter create sprout, is the folder already a Git repository?

quick drill

Which is the best commit message?

Remember

  • Edit in the folder, choose with add, save with commit.
  • One sentence per commit; if you need "and", split it.
  • Trap: committing without staging saves nothing.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSplit the work into commits

You changed PlantTile's layout and, separately, fixed a typo in the README. Describe the commands you would run to save these as two separate commits, and explain what the staging area is for.