What is a commit message?
In short, a git commit records changes to a repository.
Why a good commit message?
- Easier to review & identify potential flaws.
- Easier to do cherry-pick (https://www.previousnext.com.au/blog/intro-cherry-picking-git).
- To help future developers.
How to write a good commit message?
- One commit for one “logical change”
- Include module/feature name enclosed in [ ]
- Followed by a type of commit
- Followed by a meaningful and descriptive message
- Do include Jira bug id if the commit is fixing an issue
- Do include ticket id if it’s a new feature
Example:
git commit -m “[Module] type #id message”git commit -m “[Notifications] fix #3367 Fix unread notification count”
Types of commit messages:
build: Changes that affect the build system or external dependencies
ci: Changes to CI configuration files and scripts
docs: Documentation only changes
feature: A new feature
fix: A bug fix
perf: A code change that improves performance
refactor: A code change that neither fixes a bug nor adds a feature
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
test: Adding missing tests or correcting existing tests
Things to avoid when creating commits:
- Mixing two unrelated functional changes.
- Sending large new features in a single giant commit.
It may well be the case that the code for a new feature is only useful when all of it is present. This does not, however, imply that the entire feature should be provided in a single commit. New features often entail refactoring existing code. It is highly desirable that any refactoring is done in commits which are separate from those implementing the new feature. This helps reviewers and test suites validate that the refactoring has no unintentional functional changes. Even the newly written code can often be split up into multiple pieces that can be independently reviewed.
References:
- https://wiki.openstack.org/wiki/GitCommitMessages
- https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit
Comments
Post a Comment