Commit Message: How to write clear messages?

Commit Message: How to write clear messages?

As programmers, we often face various challenges, and one of them is naming variables. But have you ever thought about how important proper naming is in the context of commits? Initially, I struggled with this, but thanks to a certain method, my commit messages became more readable and organized. Today, I'll share this useful tip with you.

1. Build: Creating Structure and External Dependencies

Introducing changes to the build system or external dependencies can be challenging. Therefore, always label such changes appropriately. For example:

git commit -m "build: Updated gulp scripts for better task handling"

2. CI: CI Configuration and Scripts

If you make changes to configuration files or CI scripts, remember to label them accordingly. This helps easily identify changes related to continuous integration. Example:

git commit -m "ci: Updated Travis scripts to handle new dependency versions"

Tired of reading? Watch this video to see how Michał makes things quick and easy (available in Polish only).

View this post on Instagram

A post shared by Ragnarson (@ragnarsoncom)

3. Feat: New Feature

New features always require special labelling. This makes it easier to track enhancements in the code. Example:

git commit -m "feat: Added the ability to log in with a Google account"

4. Fix: Bug Fixes

Every bug fix should be clearly marked. This avoids confusion, and you can quickly identify what has been corrected. Example:

git commit -m "fix: Fixed a bug related to incorrect login form display"

5. Docs: Documentation Changes

Changes in documentation are as important as changes in code. Label them appropriately to avoid confusion with other types of commits. Example:

git commit -m "docs: Updated the user guide for new users"

6. Style: Style and Formatting Changes

Changes that affect only style, formatting, or white spaces should be labelled as "style." Example:

git commit -m "style: Fixed indentation in CSS files"

7. Refactor: Non-functional Code Improvements

If you make changes that neither fix a bug nor add a feature but improve code quality, use the "refactor" label. Example:

git commit -m "refactor: Changed variable names for better readability"

8. Perf: Performance Improvements

If you make changes to improve performance, label them as "perf." Example:

git commit -m "perf: Optimized database queries for faster data access"

9. Test: Changes in Tests

Adding new tests or improving existing ones should be labelled as a "test." This helps maintain order in the project structure. Example:

git commit -m "test: Added unit tests for the user login handling class"

Implementing this commit message convention makes a programmer's life easier. With proper labelling, both the programmer and other team members can quickly understand what exactly changed in the code. This contributes to a more readable project history and facilitates tracking progress and development.

It's worth noting that applying this convention requires discipline and consistency. However, once accustomed to it, the benefits of easier code management are invaluable.

I encourage all programmers to experiment with this convention in their projects. With it, your repositories will become more transparent, and your work on them will be more organized and efficient.