visit
Recently I asked a question on Hashnode asking users "" and I got quite some amazing responses with users explaining the conventions they use at work and for their personal projects.
In this article, I'll go over why you should write good commit messages and how you can write good commit messages.The commit command is used to save changes to a local repository after staging in Git. However, before you can save a change in Git, you have to tell Git which changes you want to save as you might have made tons of changes. A great way to do that is by adding a commit message to identify your changes.
git add static/admin/config.yml
git commit -m "Setup multiple roles for netlify-cms git gateway"
git commit -a -m "Add a new role for netlify-cms git gateway"
git add .
git commit --amend -m "Update roles for netlify-cms git gateway"
Before now, I only used
git commit -m "Fix X to allow Y to use Z"
on my personal projects with just a subject and no extra description. This is great for small and clear fixes like git commit -m "Fix typo in README.md
but in cases of more extensive changes, you would need to add some extra details.Run
git commit
without a message or option and it'll open up your default text editor to write a commit message.> To configure your "default" editor:git config --global core.editor nano
<Summarize change(s) in around 50 characters or less>
<More detailed explanatory description of the change wrapped into about 72
characters>
git commit -m "Subject" -m "Description..."
The first
-m
option is the subject (short description), and the next is the extended description (body).Ensure to check for some amazing commit message conventions or add yours to help someone make a decision.Here's a great template of a good commit message originally written by
Capitalized, short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.
Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." This convention matches up with commit messages generated by commands like git merge and git revert.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, followed by a single space, with blank lines in between, but conventions vary here
- Use a hanging indent
If you use an issue tracker, add a reference(s) to them at the bottom, like so: Resolves: #123Looks great, right? Here's how you can make yours great too:
[ You can also use emojis to represent commit types]
2. Separate the subject from the body with a blank line3. Your commit message should not contain any whitespace errors4. Remove unnecessary punctuation marks5. Do not end the subject line with a period6. Capitalize the subject line and each paragraph7. Use the imperative mood in the subject line8. Use the body to explain what changes you have made and why you made them.9. Do not assume the reviewer understands what the original problem was, ensure you add it.10. Do not think your code is self-explanatory11. Follow the commit convention defined by your teamPreviously published at //bolajiayodeji.com/writing-good-commit-messages-a-practical-guide-ck3izs56t00sed0s11z515m1j