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 withcommit.
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 creategives you a sensible.gitignore, but it does not start a repository. Rungit inityourself (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.
Look
git statusshows two modified files:lib/plant_tile.dartandREADME.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.
Which command moves a changed file into the staging area?
You edited a file but ran only git commit -m "Update". What happens?
After flutter create sprout, is the folder already a Git repository?
Which is the best commit message?
Remember
- Edit in the folder, choose with
add, save withcommit. - One sentence per commit; if you need "and", split it.
- Trap: committing without staging saves nothing.
