{"id":1166,"date":"2023-10-17T16:17:08","date_gmt":"2023-10-17T16:17:08","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1166"},"modified":"2023-10-26T16:23:21","modified_gmt":"2023-10-26T16:23:21","slug":"how-to-write-git-commit-messages","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/how-to-write-git-commit-messages\/","title":{"rendered":"How to write Git Commit Messages"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22-1024x576.png\" alt=\"\" class=\"wp-image-1167\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22-1024x576.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22-300x169.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22-768x432.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22-1536x864.png 1536w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22-850x478.png 850w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/10\/image-22.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>When developers first step into the world of Git, they often encounter a certain discomfort, especially when it comes to crafting meaningful commit messages. The Git commit message, which encapsulates the changes made and why they were made, is a crucial part of version control. Developing good committing habits early in your career is essential. In this guide, we&#8217;ll explore how to improve your Git commit messages and why it matters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Importance of Quality Commit Messages<\/h3>\n\n\n\n<p>Imagine this scenario: you open a repository, run <code>git log<\/code>, and find a list of cryptic commit messages like &#8220;Fix style&#8221; or &#8220;Update code.&#8221; Months later, you revisit the project and have no idea what these messages mean. Sound familiar? Well, this is a common issue with poorly written commit messages. Quality commit messages provide essential context and save you and your teammates time when troubleshooting or understanding past changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Anatomy of a Commit Message<\/h3>\n\n\n\n<p>A Git commit message has two main parts: the subject line and the body.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Subject Line:<\/strong> This should be concise, not exceeding 50 characters. It should start with a capital letter and use the imperative mood (e.g., &#8220;Add,&#8221; &#8220;Fix,&#8221; &#8220;Update&#8221;). The subject line provides a high-level overview of the change.<\/li>\n\n\n\n<li><strong>Body:<\/strong> The body of the message is where you can explain in more detail. It should be wrapped at 72 characters and answer the questions of &#8220;why&#8221; and &#8220;what.&#8221;<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Writing Better Commit Messages<\/h3>\n\n\n\n<p>Let&#8217;s dive into practical steps to improve your commit messages:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Capitalization and Punctuation<\/h4>\n\n\n\n<p>Always start the subject line with a capital letter and don&#8217;t end it with punctuation. Conventional Commits, a popular convention, encourages using all lowercase.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. Mood Matters<\/h4>\n\n\n\n<p>Use the imperative mood in the subject line. This creates a tone of giving an order or request. For example, &#8220;Fix the dark mode toggle state&#8221; is more appropriate than &#8220;Fixed the dark mode toggle state.&#8221;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. Specify the Type of Commit<\/h4>\n\n\n\n<p>It&#8217;s beneficial to categorize your commits. Use a consistent set of words to describe your changes. For example, &#8220;Bugfix,&#8221; &#8220;Update,&#8221; &#8220;Refactor,&#8221; or &#8220;Bump.&#8221; This helps in classifying and searching for specific types of changes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Watch the Length<\/h4>\n\n\n\n<p>Keep the subject line short, ideally under 50 characters, and restrict the body to 72 characters per line. This ensures messages are concise and readable.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">5. Content Clarity<\/h4>\n\n\n\n<p>Be direct and avoid filler words and phrases. Think like a journalist, aiming to answer the &#8220;what&#8221; and &#8220;why&#8221; questions. Pretend that the reader has no prior knowledge of the change and needs a clear explanation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conventional Commits<\/h3>\n\n\n\n<p>Conventional Commits is a widely adopted format that provides structured commit messages. It uses the format: <code>&lt;type&gt;[optional scope]: &lt;description&gt;<\/code>. The <code>type<\/code> can include values like &#8220;feat&#8221; (new feature), &#8220;fix&#8221; (bug fix), &#8220;chore&#8221; (maintenance), and more. The optional scope specifies the part of the codebase affected, and the description provides a concise summary.<\/p>\n\n\n\n<p>This convention enhances consistency in commit messages and can be paired with tools like Commitizen to enforce standards.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Commit Message Comparisons<\/h3>\n\n\n\n<p>Let&#8217;s compare some examples to see the difference quality commit messages make:<\/p>\n\n\n\n<p><strong>Good:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>feat: Improve performance with lazy load implementation for images<\/code><\/li>\n\n\n\n<li><code>chore: Update npm dependency to the latest version<\/code><\/li>\n\n\n\n<li><code>Fix bug preventing users from submitting the subscribe form<\/code><\/li>\n\n\n\n<li><code>Update incorrect client phone number within the footer body per client request<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>Bad:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Fixed bug on the landing page<\/code><\/li>\n\n\n\n<li><code>Changed style<\/code><\/li>\n\n\n\n<li><code>Oops<\/code><\/li>\n\n\n\n<li><code>I think I fixed it this time?<\/code><\/li>\n\n\n\n<li>Empty commit messages<\/li>\n<\/ul>\n\n\n\n<p>By following these guidelines, your commit messages can become valuable documentation, saving you and your team time and frustration. Whether you&#8217;re working solo or in a collaborative development environment, investing a little extra effort in crafting clear and meaningful commit messages pays off in the long run.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When developers first step into the world of Git, they often encounter a certain discomfort, especially when it comes to crafting meaningful commit messages. The Git commit&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[469,467,466,468],"class_list":["post-1166","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-commit-message-comparisons","tag-git-commit-messages","tag-how-to-write-git-commit-messages","tag-importance-of-quality-commit-messages"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=1166"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":1168,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1166\/revisions\/1168"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}