Write Better Commit Messages

  • vnull
  • Pub Dec 27, 2022
  • Edited Jan 8, 2023
  • 3 minutes read

GIT OOPS!

Question
Yep… I have absolutely no idea what I meant by ‘Fix foobar’ 6 months ago.

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'
Tip
VScode Git Blame extension adds git blame information to your vscode compatible view. Git historical information are Git History and GitLens.

Example commit types:

  • feat – a new feature is introduced with the changes
  • fix – a bug fix has occurred
  • chore – 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 feature
  • docs – updates to documentation such as a the README or other markdown files
  • style – 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 tests
  • perf – performance improvements
  • ci – continuous integration related
  • build – changes that affect the build system or external dependencies
  • revert – 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.

Do you have an idea or suggestion for a blog post? Submit it here!

Related Posts

2023 Phoenix VMUG UserCon

  • vnull
  • Sep 8, 2023
  • 4 minutes read

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 more

Red Hat User Group Insights, Ansible Automation Platform, and ITSM Integration

  • vnull
  • Jun 1, 2023
  • 3 minutes read

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 more

Robocopy Examples

  • vnull
  • Feb 10, 2023
  • 5 minutes read

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