Commits
🏠The everyday picture
A photograph of the whole project at one moment, with a caption on the back: "Added the contact page." A commit is that photo.
📘What it really is
- A commit is a saved snapshot of the project, with a message, an author and a date.
- Saving a commit takes two steps:
git addchooses which changes go into the snapshot (next lesson);-
git commit -m "message"takes the snapshot. -
Good commit messages say what changed and why, in a short sentence: "Add contact form" is better than "update" or "stuff".
-
Commit small and often: one finished change per commit. Small commits are easy to understand and easy to undo.
- Every commit gets a unique ID (a hash), like
85832ed. You saw these in your test site's deploy log.
🖱️Try it
git add index.html .gitignore
git commit -m "Start my first site"
git status
git status should now say "nothing to commit, working tree clean". That means everything is saved in
history.
✅Quick check
Which is the better commit message: "changes" or "Fix the broken link on the home page"? Why?
Show the answer
The second. In six months, it tells you exactly what that commit did without opening it.
Why commit small and often instead of once at the end of the day?
Show the answer
Each small commit is easy to understand and can be undone on its own, without losing the rest of the day's work.
