0
0
Gitdevops~5 mins

Writing good commit messages in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
Good commit messages help you and others understand what changes were made and why. They make it easier to track history and fix problems later.
When you finish a small task or fix a bug and want to save your work with a clear explanation
When you want to share your changes with teammates so they understand your work
When you prepare code for a review and want to explain your changes clearly
When you want to keep a clean project history that is easy to read and search
When you need to find why a change was made during debugging or audits
Commands
This command creates a commit with a short, clear message explaining the fix made to the login error.
Terminal
git commit -m "Fix login error by correcting password check"
Expected OutputExpected
[master abc1234] Fix login error by correcting password check 1 file changed, 5 insertions(+), 2 deletions(-)
-m - Allows you to write the commit message directly in the command line
This command opens the default text editor so you can write a detailed commit message with a subject and body.
Terminal
git commit
Expected OutputExpected
Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit.
This command shows the most recent commit message and details to verify your commit was saved correctly.
Terminal
git log -1
Expected OutputExpected
commit abc1234def5678ghijklmno1234567890abcdef12 (HEAD -> master) Author: Your Name <you@example.com> Date: Wed Apr 24 12:00:00 2024 +0000 Fix login error by correcting password check
-1 - Shows only the latest commit
Key Concept

If you remember nothing else from this pattern, remember: write clear, concise commit messages that explain what changed and why.

Common Mistakes
Writing vague commit messages like 'fix' or 'update'
These messages do not explain what was fixed or updated, making it hard to understand the change later.
Write specific messages like 'Fix login error by correcting password check' that describe the change clearly.
Writing very long commit messages without a clear subject line
Long messages without a summary make it hard to quickly scan commit history.
Start with a short subject line (50 characters or less), then add a blank line and a detailed explanation if needed.
Not committing related changes together
Mixing unrelated changes in one commit makes it harder to understand and revert specific changes.
Group related changes into separate commits with clear messages for each.
Summary
Use 'git commit -m "message"' to write short, clear commit messages quickly.
Use 'git commit' without -m to write detailed messages in your editor.
Use 'git log -1' to check your latest commit message and details.