Sub topic 1
Why Conventional Commits Improve Git History
Prerequisites
This chapter assumes you can use git add, git commit, and git log. You should also understand branches and the basic MAJOR.MINOR.PATCH form of Semantic Versioning.
Why a Commit Convention Is Worth the Effort
A commit convention is a shared rule for writing commit messages. Without one, a project history may contain messages such as “updates,” “fixed stuff,” and “final changes.” These messages are difficult to search and do not explain what changed.
Conventional Commits gives each message a predictable structure. People can scan the history quickly, search for a kind of change, and understand the purpose of a commit without opening every file. Tools can also use the structure to create changelogs or identify release-worthy changes.
The Structure: Type, Scope, Description, Body, Footers
A conventional commit starts with a type, followed by an optional scope, a colon, a space, and a short description.
type(scope): description
Optional explanation of the change.
Optional footer: valueThe scope gives more context, such as parser or api. The body explains motivation or important details. Footers contain references or metadata. The body and footers are optional.
| Part | Purpose | Example |
|---|---|---|
| Type | Classifies the change | `fix` |
| Scope | Names the affected area | `parser` |
| Description | Summarizes the change | `handle empty input` |
Choosing a Type: `feat`, `fix`, and the Rest
Choose the type based on the user-visible or maintenance purpose of the change.
feat: adds a capability.fix: corrects a defect.docs: changes documentation.test: changes tests.refactor: changes structure without changing behavior.perf: improves performance.build,ci,chore, andstyle: cover tooling, automation, maintenance, or formatting.
For example:
feat(search): support filtering by author
fix(parser): prevent crash on empty input
docs(api): clarify authentication errorsAdding a Scope for Context
A scope is useful when the repository has recognizable areas. Use a consistent name that teammates can understand. Good scopes might be api, parser, web, or database.
Do not invent a new scope for every file. If no useful area exists, omit the scope:
fix: prevent crash when the config file is emptyExercise
Write a conventional commit for adding CSV export to a reporting module.
Show answer
feat(reports): add CSV export