fix: Fixing a Bug
Learn how to write a proper fix commit message for bug fixes. Includes format rules, examples of good and bad descriptions, and guidance on referencing issue trackers.
Detailed Explanation
The fix Commit Type
The fix type is used when your commit patches a bug in the codebase. Under Semantic Versioning, a fix commit triggers a patch version bump (e.g., 1.2.1 to 1.2.2), indicating that existing functionality has been corrected without introducing new features or breaking changes.
Example Message
fix: prevent crash when user profile is null
When to Use fix
Use fix when your commit:
- Corrects incorrect behavior or output
- Resolves a crash, exception, or error
- Fixes a regression introduced by a previous commit
- Patches a security vulnerability
- Corrects a data handling or validation issue
Referencing Issues
It is good practice to reference the issue or bug ticket in the footer:
fix: prevent crash when user profile is null
Check for null profile before accessing display name.
Previously, new users without a completed profile would
cause a TypeError on the dashboard page.
Closes #542
The Closes #542 footer tells GitHub (and similar platforms) to automatically close issue #542 when this commit is merged. Other common keywords include Fixes, Resolves, and Refs.
Common Mistakes
| Bad | Why | Better |
|---|---|---|
fix: fixed the bug |
Past tense, vague | fix: prevent null pointer on dashboard |
fix: Bug fix. |
Period at end, vague | fix: resolve incorrect date parsing |
fix: Fix issue #123 |
Uppercase, just repeats ticket | fix: handle empty response from API |
Choosing Between fix and refactor
If you are restructuring code that happens to fix a bug, use fix. The type describes the impact, not the technique. Use refactor only when behavior is unchanged.
Use Case
A user has reported that the application crashes when they try to access the settings page without having completed their profile setup. You have identified the null reference error and added a guard check. You need a commit message that communicates the fix and links it to the bug report.