Commits: saving your work
A commit is a snapshot of your project at one moment, with a short note explaining what changed. It's the single most important idea in Git.
Think of commits like save points in a video game. Each time you clear a level, you save. If something goes wrong later, you can go back to any save point. A commit is that save point for your code.
Why not just press Ctrl+S?
Saving a file writes the latest version to disk — but it forgets the previous one. A commit is different: it keeps every version. After ten commits, you can look at any of the ten and see exactly what the project looked like then, and what changed between them.
Each commit also records who made it, when, and a message saying why. Six months later, when a payment bug appears, you can find the exact commit that introduced it and read the reasoning behind it.
The two-step: stage, then commit
Git makes you do two small steps. This feels odd at first but it's useful.
1. Stage the changes you want in this snapshot:
git add checkout.js
Staging is you saying "include this file in my next commit." You can stage some files and leave others out — handy when you've changed several things but want to save them as separate, tidy snapshots.
2. Commit the staged changes with a message:
git commit -m "Add GST calculation to the checkout total"
That's it. You've made a save point.
To stage everything you changed at once:
git add .
git commit -m "Fix UPI refund rounding error"
Writing a good commit message
The message is a note to your future teammates (and future you). Good messages explain the why, not just the what.
- 🚫
fixed stuff - 🚫
changes - ✅
Fix refund amount rounding for UPI payments - ✅
Add Hindi translation for the login screen
A simple rule: finish the sentence "If applied, this commit will…". → "…fix refund amount rounding."
Seeing your history
git log --oneline
You'll see something like:
a1b2c3d Fix refund amount rounding for UPI payments
9f8e7d6 Add GST calculation to the checkout total
3c2b1a0 Set up the checkout page
Each line is one commit. That short code (a1b2c3d) is the commit's unique ID — you can use it to jump back to that exact snapshot.
Habit to build: commit often, in small pieces. Ten small commits that each do one thing are far easier to understand — and to undo — than one giant commit that changes everything.