Making Commits and Writing Good Messages
10 min read
Your First Commit
A commit is a permanent snapshot of your staged changes. Each commit has a unique SHA-1 hash, an author, a timestamp, and a message.
bash
git commit -m 'add homepage HTML structure'
git commit # opens your editor for a multi-line messageThe Anatomy of a Good Commit Message
A well-written message saves your future self and your teammates enormous time. Follow the seven-rule style used by most open-source projects and teams like CPCODELAB:
- Subject line: 50 characters or fewer, imperative mood ("fix", "add", "remove").
- Blank line separating subject from body.
- Body: explain *why*, not *what*. The diff already shows what changed.
- Wrap body at 72 characters.
- Reference issues when relevant:
closes #42.
text
fix: validate email before saving to database
The previous code accepted any string as an email address,
causing silent failures when sending confirmation emails.
Added a regex check and return a 400 if validation fails.
Closes #17Common Prefixes (Conventional Commits)
feat:— a new featurefix:— a bug fixdocs:— documentation onlyrefactor:— code change that neither fixes a bug nor adds a featurechore:— build process, tooling changes
Avoid messages like "stuff" or "fix bug". At CPCODELAB, seniors review your commit history during PR review. Vague messages slow down review and reflect poorly on the author.
Ready to test yourself?
Practice Git & GitHub— quiz & coding exercises