How can writing good commit messages make your work better?
This is a simple guide to using better commit messages on Git so that your work and contributions can be better understood by fellow contributors.
Git is a boon for collaborative work. It allows multiple contributors to work simultaneously on a single project and also allows for any changes to be tracked and reversed. When working in large teams, the number of commits can get hard to manage and messy commit messages only make it harder for the team to work efficiently.
The easy workaround for this is to write good commit messages. We can do this by prefixing our message with a term to describe the change made. Let us have a look at some common changes and how we can write the message for them.
feat
A new feature has been added.
We can use this term as prefix when we add a totally new feature or functionality to the project we are building.
For example, if we have a game and we add a new weapon named ‘X21’ to the game, the commit message would be as-
[feat: added weapon- X21]
fix
Bug fixes.
This term is used when we fix an existing bug in the program. We can add a note about the bug that was fixed and how it was fixed. Let’s consider we’re fixing a bug where the looping variable was not being incremented.
[fix: fixed loop- increment looping variable]
docs
Changes in documentation.
This is usually with reference to the additional documentation that goes into a project, like the readme file or the license file. An example message would be-
[docs: added readme.md]
style
Changes related to styling.
This refers to any changes made with respect to how the application looks. Usually in web development, this means all the changes regarding the CSS part of the project.
[style: added button hover animations]
refactor
Changing the structure of the code.
This refers to any changes made in the code which do not fix a bug nor do they affect the functionality of the code. It could be something like changing the names of a variable or moving blocks of code in the program.
[refactor: renamed variable ‘money’ to ‘dollars’]
test
All changes related to testing.
This tag will be used for all changes related to testing of the code. Even refactoring of existing tests should be marked under this tag.
[test: dummy variables added to test function edge case]
chore
Updating build tasks, package manager configs and other miscellaneous tasks. There will be no change in the production code for the changes implemented here.
[chore: completed build task]
These are some of the tags you can use to improve your commit messages. Your team will surely appreciate you for it!
Happy coding!