Write Better Commit Messages
GIT OOPS!
Trying to write better commits fixed bug on landing page
vs. fix: bug preventing users from submitting the subscribe form
Assuming you already understand basic Git workflow. If not, I suggest reading through the Git Handbook.
It is also important to note that you should follow your team’s conventions
The Anatomy of a Commit Message Basic:
git commit -m <message>
Detailed:
git commit -m <title> -m <description>
Tthoughtful commits, consider the following:
- Why have I made these changes?
- What effect have my changes made?
- Why was the change needed?
- What are the changes in reference to?
Assume the reader does not understand what the commit is addressing.
Make clear why that change was made, and note if it is crucial for the functionality or not.
Example:
git commit -m 'Add wdiget'
git commit -m 'Add wdiget to nav items to prevent them from overlapping the logo'
Example commit types:
feat
– a new feature is introduced with the changesfix
– a bug fix has occurredchore
– changes that do not relate to a fix or feature and don’t modify src or test files (for example updating dependencies)refactor
– refactored code that neither fixes a bug nor adds a featuredocs
– updates to documentation such as a the README or other markdown filesstyle
– changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.test
– including new or correcting previous testsperf
– performance improvementsci
– continuous integration relatedbuild
– changes that affect the build system or external dependenciesrevert
– reverts a previous commit
Full Conventional Commit Example
fix: fix foo to enable bar
This fixes the broken behavior of the component by doing xyz.
BREAKING CHANGE
Before this fix foo wasn't enabled at all, behavior changes from <old> to <new>
Closes XXXX-12345
Example conventions, it’s helpful to include guidelines for commits in a contributing or README markdown file within your projects.
Learn more about Conventional Commit SemVer.org and here.
Commit Message Comparisons
Good
- feat: improve performance with lazy load for images
- chore: update python dependency to latest version
- fix: bug preventing users from submitting the subscribe form
- update: incorrect client phone number within footer body per client request
Bad
- fixed bug on landing page
- Changed style
- oops
- I think I fixed it this time?
- empty commit messages
Summary
Writing good commit messages is an extremely beneficial skill, and it helps to communicate and collaborate. Commits serve as an archive of changes. Need to establish a set of agreed-upon standards that can be followed, but as long as your team agrees upon a convention.
Related Posts
2023 Phoenix VMUG UserCon
Introduction: The recent 2023 Phoenix VMUG UserCon brought together some like-minded people in the field, with discussions ranging from VMware technologies to best practices for optimizing existing systems.
Read moreRed Hat User Group Insights, Ansible Automation Platform, and ITSM Integration
Introduction: This blog post aims to summarize the key takeaways from this informative workshop. At the recent Red Hat User Group workshop on Red Hat Insights, Red Hat Ansible Automation Platform, and their integration with management (ITSM) systems, such as ServiceNow, provided valuable insights into how these technologies work together.
Read moreRobocopy Examples
Robocopy Examples Robocopy has many command line options and it can be overwhelming to know which commands to use. In this post, we will take a look at how to ues robocopy to copy, mirror, purge Files and Folders.
Read more