What makes a good commit?
When a fellow developer reads through the commits,the commit message should convey the information very clearly and quickly. The following things can be used —
- Why the commit is needed? Is it for a Bug fix? Or a feature? Or just a refactor?
- What does the commit address and how?
- Can the commit be linked to external systems( JIRA, BugZilla or gitlab issues)
A better commit template :
← Start of commit template →
[Fix/Feature/Refactor] : [Type commit title here]
[Type commit explaination here]
Tracking ID : [Type Tracking ID Here]
← End of commit template →
How would this benifit large teams?
As the team size grows, individual developer characteristics would bring in inconsistancy in commit messages. Having a common commit template would make commit messages more consistent and predictable. Over a period of time, browsing through commit messages would become seemless and can be understood easily. Also, for the new joinees scanning the commit history would be really helpful.
How would the tracking id help?
- Linking commits to specific features tracked through tools like JIRA
- In the CI pipelines. Using the tracking id, CI systems could query tracking systems like JIRA, Gitlab, Bugzilla for statuses. Ex . Suppose there is a CI pipeline, that has to accept a merge request only if the status of feature is QA-Signed off, the tracking id would come in handy. While the merge request is raised, the CI pipeline that follows the merge request could parse through the commit messages. Post that it can extract thetracking id, query the tracking systems for the details. If status is QA-Signed off, only then accept the merge request, else reject the merge request right away.
Is there a way to automatically show the template on every commit?
Oh yes. Thats where git config comes in handy.
- Create a file containing the commit template and name it say .customtemplate.txt
- Edit git config
3. Try git commit now, and the template would appear right away and you can just edit the template to fit in your comments
Is there a way to enforce the commit message format?
Commit hooks like post commit hooks, pre commit hooks lets us run certain scripts on the the respective events. This would allow us to fail or accept the commit based on certain conditions.
Its very important to have a standard when scaling up teams. Especially in our case where we have more than 20 developers for our Android app development. Engineering process stanards become paramount — for Engineering Managers to review code and ask the right questions, this could be very helpful.