“Good Commit” vs “Your Commit”: How to Write a Perfect Git Commit Message
A good commit shows whether a developer is a good collaborator — Peter Hutterer, Linux.
Years ago, I never realized there were specific rules for writing commit messages until my curiosity got the best of me. I used to think that straightforward messages like “added feature 2,” “fixed the bug on the Main Navigation bar,” or even “foo” were sufficient. The conviction that commit messages went largely unread proved mistaken. In reality, well-crafted commit messages are indispensable, ensuring that our future selves benefit from our diligence and thoughtfulness.
Contents: Why you should care | Common Mistakes | The 7 Rules | Case Study | Tips.
Why should we care about writing clean commit message?
Commits serve as the tangible building blocks of a programmer’s craft. They act as the icing on the cake of code, and when written correctly, they bring substantial value. A well-written commit message becomes indispensable because they provide context — otherwise a commit message wouldn’t be needed at the first place.
A good commit shows whether a developer is a good collaborator — Peter Hutterer, Linux.
A common mistake among developers is treating the Git repository as a backup system. Randomly committing to capture the current state of code can impede your ability to comprehend past changes when checking out the codebase in the future. Commit messages like “WIP”, “Off for lunch”, “End of code for today”, “I am tired AF”, “Happy Weekend Team”, and “First to commit” will only clutter your Git log, making it difficult to understand the essential commits you’ve made because none of these messages consists of any additional value.
Here are some key mistakes to avoid when attempting to commit to a remote repository
Never Commit Changes for Different Files Separately
Committing changes to different files separately might lead to problems when reviewing the commit history or collaborating with other team members. It becomes…