<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marcos Junior </title>
    <description>The latest articles on DEV Community by Marcos Junior  (@codermarcos).</description>
    <link>https://dev.to/codermarcos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F365046%2Fa06ae2af-e6fe-4b45-9735-e00c35196c57.jpeg</url>
      <title>DEV Community: Marcos Junior </title>
      <link>https://dev.to/codermarcos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codermarcos"/>
    <language>en</language>
    <item>
      <title>What is a good message and size for a commit?</title>
      <dc:creator>Marcos Junior </dc:creator>
      <pubDate>Fri, 01 Mar 2024 13:22:16 +0000</pubDate>
      <link>https://dev.to/codermarcos/what-is-a-good-message-and-size-for-a-commit-2edd</link>
      <guid>https://dev.to/codermarcos/what-is-a-good-message-and-size-for-a-commit-2edd</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnk0xij6bc3wloiyp1tff.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnk0xij6bc3wloiyp1tff.jpg" alt="Developer creating code and it turn into a bug which will be eaten by the developer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First of all, why should I have to write a commit message? Git already generates a unique hash, so why is it required?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.tenor.com%2FE3WCe-24PIsAAAAd%2Fobama-why.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.tenor.com%2FE3WCe-24PIsAAAAd%2Fobama-why.gif" alt="Why?"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Actually, it is not required. You can make a Git commit without a message using this flag &lt;code&gt;--allow-empty-message&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;--allow-empty-message&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, I don't recommend you do it, even though you've already made at least one commit with a message like these:&lt;/p&gt;

&lt;p&gt;❌ &lt;code&gt;.&lt;/code&gt;&lt;br&gt;
❌ &lt;code&gt;last update&lt;/code&gt;&lt;br&gt;
❌ &lt;code&gt;more changes&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So, what will we see here? Basically, how to make good commits. It includes message, size, and order, which are just suggestions.. &lt;/p&gt;

&lt;p&gt;At the end of this text I'll bring some tools that help us to follow this tips and write good messages.&lt;/p&gt;

&lt;h2&gt;
  
  
  🏁 Let's see how to make graceful commits!
&lt;/h2&gt;

&lt;p&gt;I would like to start by talking about the message, but the first step to having a good message is to define a good size for our commits.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fc.tenor.com%2FTRINhXgdV60AAAAC%2Ftenor.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fc.tenor.com%2FTRINhXgdV60AAAAC%2Ftenor.gif" alt="The size matter honey"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  📐 What's a good size for a commit?
&lt;/h3&gt;

&lt;p&gt;There is no exact size, but there are some guidelines that it would be very good for you to follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Atomicity&lt;/strong&gt;: Each commit should focus on solving one specific problem or implementing something.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Clarity and Readability&lt;/strong&gt;: Commits should be clear and easily understandable. A commit should be self-contained and not rely on other commits to make sense.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Frequency&lt;/strong&gt;: Commits should be made frequently but not too often. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Testability&lt;/strong&gt;: The changes introduced by a commit should not break existing tests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Revertibility&lt;/strong&gt;: If a commit introduces a bug or unintended consequence, it should be easy to revert the commit without affecting other parts of the codebase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Reviewability&lt;/strong&gt;: Keeping commits small and focused makes it easier for team members to review code changes and provide feedback.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ &lt;strong&gt;Consistency&lt;/strong&gt;: Consistency helps in understanding the development history of the codebase and makes it easier to navigate through commit logs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Considering these ideas, there are some ways to decide how to split our commits into smaller commits. Some of these are:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gifer.com%2Fembedded%2Fdownload%2FIDIc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gifer.com%2Fembedded%2Fdownload%2FIDIc.gif" alt="spliting a cake"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Functional Changes vs Refactoring&lt;/strong&gt;: Separate commits for functional changes (adding new features, fixing bugs) from commits that focus on refactoring or improving code quality without changing behavior. This helps in reviewing and understanding the changes more effectively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Critical vs Non-Critical Changes&lt;/strong&gt;: If your changes include both critical (e.g., security fixes, major bug fixes) and non-critical changes, consider splitting them into separate commits. This allows critical changes to be reviewed and deployed more quickly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User-Facing vs Internal Changes&lt;/strong&gt;: Separate commits that affect the user interface or user experience from commits that are purely internal (e.g., performance optimizations, code reorganization). This makes it easier to understand the impact on end-users.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I would like to talk about a pattern that I have been following, which uses a little bit of each of those. For this, I will use an example of frontend code, but it can be applied to everything.&lt;/p&gt;

&lt;p&gt;Imagine that we are adding a feature for translation to a small application. For this hypothetical feature, I have these changes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqngqcyvswhye3ntfnh0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqngqcyvswhye3ntfnh0k.png" alt="File changes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's evident that there have been a very small number of changes. But I would split them into &lt;strong&gt;4 commits&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;1 . First with these 2 json translation files&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;public/locales/en/login.json&lt;/li&gt;
&lt;li&gt;public/locales/pt/login.json&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These files are new and not yet used in any part of our application, so they don't pose any risk. I commit them first. However, it's good to keep them separate from other new files because this code has a direct impact on the users.&lt;/p&gt;

&lt;p&gt;2 . Second with 2 files which inserts the new package&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;package.json&lt;/li&gt;
&lt;li&gt;package-lock.json&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping only these two files in this commit will make it easy to find who inserted, removed, or upgraded a package in the project.&lt;/p&gt;

&lt;p&gt;3 . Third with 1 new file which are not imported yet&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;src/i18n.ts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is new code that is not imported by any part of our code, so it doesn't pose any risk. Additionally, it is an internal change that doesn't have a direct impact on the user.&lt;/p&gt;

&lt;p&gt;4 . Fourth with 1 the change at the existing component&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;src/App.tsx&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, the most "dangerous" change, where I modified an existing file. It's better to keep it separate so that in case of rollback, I only need to rollback this part.&lt;/p&gt;

&lt;p&gt;To clarify the risk, imagine that all changes carry a certain level of risk, which is determined by their probability and severity:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1hwd8vb7ocjvjk7yf02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1hwd8vb7ocjvjk7yf02.png" alt="Risk of code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Based on this, it is easier to determine which changes need to be committed separately for ease of rollback.&lt;/p&gt;

&lt;h3&gt;
  
  
  📝 What is a good message for a commit?
&lt;/h3&gt;

&lt;p&gt;Now, returning to our initial question, why should I have to write a commit message?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Logical reasoning doesn't come only from mathematics, it also comes from life.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F176aoz242krvqd1kzexl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F176aoz242krvqd1kzexl.png" alt="Draw into a cave"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same reason of our ancestors 40.000 B.C. as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Communication&lt;/li&gt;
&lt;li&gt;Learn and Teach&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the most important thing for us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Help someone who saw that&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The message will guide and help who needs find something in our code. Sometimes it will be unimportant, and sometimes this will help recover the functional state of our product.&lt;/p&gt;

&lt;p&gt;So for it there are some patterns which you can follow such as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.conventionalcommits.org/en/v1.0.0/#specification" rel="noopener noreferrer"&gt;Conventional Commits&lt;/a&gt;&lt;br&gt;
&lt;code&gt;feat(service)!: add integration with xpto&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://gitmoji.dev/" rel="noopener noreferrer"&gt;Gitmoji&lt;/a&gt;&lt;br&gt;
&lt;code&gt;✨ add integration with xpto&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/atom/.github/blob/master/CONTRIBUTING.md#git-commit-messages" rel="noopener noreferrer"&gt;Atom&lt;/a&gt;&lt;br&gt;
&lt;code&gt;🎨 Add integration with xpto&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom: You can define it as you prefer, just document it.&lt;br&gt;
&lt;code&gt;🆕 [FF-666] add integration with xpto&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Try using emoji as a prefix in your commit message! It can be very helpful, similar to how the trash bin is colorful and easily recognizable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftqqjhxtncat2dqe0r4b1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftqqjhxtncat2dqe0r4b1.png" alt="Recycle bin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't you believe me? Look at the following example: try to find the commit where I 🔥 remove a file!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fczrmf6ja9etkhzip4xri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fczrmf6ja9etkhzip4xri.png" alt="Difference between conventional commits vs git emoji"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Tools to help us with commits
&lt;/h3&gt;

&lt;p&gt;Finally here we have some tools to help us follow the patterns and define our messages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/Nutlope/aicommits" rel="noopener noreferrer"&gt;AI Commit&lt;/a&gt; Use AI to write the commit messages&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/features/copilot" rel="noopener noreferrer"&gt;Copilot&lt;/a&gt; Configure git for use your editor with copilot and he'll help you write your commit message&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/commitizen/cz-cli" rel="noopener noreferrer"&gt;Commitizen&lt;/a&gt; Define a interface to write your commits and automatically and a prefix and a suffix to your message. (&lt;em&gt;and others features not related&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's all thanks for read!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>git</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
