Bird
Raised Fist0
Gitdevops~10 mins

Writing good commit messages in Git - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Writing good commit messages
Start Commit
Write short summary (<=50 chars)
Add blank line
Write detailed description
Review message
Save and close commit
Commit recorded
This flow shows the steps to write a clear and helpful git commit message, starting with a short summary, then a blank line, followed by a detailed description.
Execution Sample
Git
git commit -m "Fix login bug"

# Detailed message:
# The login failed due to missing token check.
# Added token validation to fix the issue.
This commit message has a short summary and a detailed explanation separated by a blank line.
Process Table
StepActionMessage PartResult
1Write short summaryFix login bugSummary line created
2Add blank lineBlank line added after summary
3Write detailed descriptionThe login failed due to missing token check. Added token validation to fix the issue.Detailed description added
4Review messageFix login bug The login failed due to missing token check. Added token validation to fix the issue.Message ready to save
5Save and close commitCommit recorded with message
💡 Commit message saved and commit recorded in git history
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
commit_messageFix login bugFix login bug Fix login bug The login failed due to missing token check. Added token validation to fix the issue.Fix login bug The login failed due to missing token check. Added token validation to fix the issue.
Key Moments - 3 Insights
Why do we add a blank line after the short summary?
The blank line separates the summary from the detailed description, making the message easier to read and follow, as shown in step 2 of the execution_table.
Can the short summary be too long?
Yes, it should be 50 characters or less to keep it concise and clear, as demonstrated in step 1 where the summary is short and direct.
What if I skip the detailed description?
Skipping the detailed description can make it harder for others to understand the reason behind the change. Step 3 shows adding details improves clarity.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the commit_message after step 3?
AFix login bug The login failed due to missing token check. Added token validation to fix the issue.
BFix login bug
Cgub nigol xiF
DThe login failed due to missing token check.
💡 Hint
Check the commit_message value in variable_tracker after step 3
At which step is the blank line added in the commit message?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Message Part' columns in execution_table for the blank line addition
If the short summary is longer than 50 characters, what is the likely effect?
AThe commit message will be rejected by git
BThe detailed description will be ignored
CThe message will be harder to read and less clear
DThe commit will fail to save
💡 Hint
Refer to key_moments about summary length and clarity
Concept Snapshot
Writing good commit messages:
- Start with a short summary (<=50 chars)
- Add a blank line after summary
- Write a detailed description explaining the change
- Review message before saving
- Clear messages help team understanding
Full Transcript
To write a good git commit message, start by writing a short summary line that briefly describes the change. This summary should be 50 characters or less to keep it concise. Next, add a blank line to separate the summary from the detailed description. Then write a detailed explanation of what was changed and why. Review the entire message to ensure clarity and helpfulness. Finally, save and close the commit message to record the commit. This process helps keep commit history clear and useful for everyone on the team.

Practice

(1/5)
1. What is the main purpose of a good commit message in Git?
easy
A. To list all files changed in the commit
B. To explain what changes were made and why
C. To include the entire code change in the message
D. To write a long story about the project history

Solution

  1. Step 1: Understand the role of commit messages

    Commit messages should clearly explain what was changed and why, helping others understand the purpose.
  2. Step 2: Identify the best option

    To explain what changes were made and why correctly states the purpose, while others focus on irrelevant or incorrect details.
  3. Final Answer:

    To explain what changes were made and why -> Option B
  4. Quick Check:

    Good commit message = explain what and why [OK]
Hint: Focus on explaining changes and reasons, not details [OK]
Common Mistakes:
  • Listing files instead of explaining changes
  • Writing too much unrelated history
  • Including code in the message
2. Which of the following is the correct format for a good Git commit message?
easy
A. A message with only emojis
B. A long paragraph without a summary line
C. Only a list of changed files
D. A short summary line followed by a blank line and detailed explanation

Solution

  1. Step 1: Recall Git commit message format

    A good commit message starts with a short summary line, then a blank line, then optional details.
  2. Step 2: Match options to format

    A short summary line followed by a blank line and detailed explanation matches this format exactly; others do not follow best practices.
  3. Final Answer:

    A short summary line followed by a blank line and detailed explanation -> Option D
  4. Quick Check:

    Summary line + blank line + details = correct format [OK]
Hint: Use a short summary line, then details after a blank line [OK]
Common Mistakes:
  • Skipping the blank line between summary and details
  • Writing only a long paragraph
  • Using emojis without explanation
3. Given this commit message:
Fix login bug
What is missing to make it a good commit message?
medium
A. A detailed explanation of why the bug was fixed
B. A list of all files changed
C. A longer summary line
D. The author's email

Solution

  1. Step 1: Analyze the commit message content

    The message only has a short summary but lacks explanation of why the bug was fixed.
  2. Step 2: Identify what improves clarity

    Adding a detailed explanation helps others understand the reason behind the fix.
  3. Final Answer:

    A detailed explanation of why the bug was fixed -> Option A
  4. Quick Check:

    Good message = what + why, missing why here [OK]
Hint: Add why the change was made, not just what [OK]
Common Mistakes:
  • Only writing a short summary
  • Listing files instead of explanation
  • Adding unrelated info like author email
4. You wrote this commit message:
fix login bug
What is the main problem with this message?
medium
A. It includes a blank line after the summary
B. It is too long and detailed
C. It uses lowercase and lacks a capitalized summary
D. It uses past tense instead of present tense

Solution

  1. Step 1: Check capitalization in commit messages

    Good commit messages start with a capitalized summary line.
  2. Step 2: Evaluate the given message

    The message starts with lowercase 'fix', which is not recommended.
  3. Final Answer:

    It uses lowercase and lacks a capitalized summary -> Option C
  4. Quick Check:

    Summary line should start capitalized [OK]
Hint: Always capitalize the first letter of the summary line [OK]
Common Mistakes:
  • Starting summary with lowercase letter
  • Making summary too long
  • Ignoring tense conventions
5. You want to write a commit message for adding a new feature that improves search speed by caching results. Which commit message is best?
hard
A. Add caching to improve search speed Implemented a cache layer to store recent search results, reducing response time.
B. Improved search speed by adding cache Cache added.
C. Added cache This commit adds cache.
D. Fix search speed Cache implemented.

Solution

  1. Step 1: Evaluate clarity and detail in options

    Add caching to improve search speed Implemented a cache layer to store recent search results, reducing response time. has a clear summary and detailed explanation of what and why.
  2. Step 2: Compare other options

    The other options are vague, use incorrect tense or verbs (such as 'Fix' for a new feature), or lack detailed explanation.
  3. Final Answer:

    Add caching to improve search speed Implemented a cache layer to store recent search results, reducing response time. -> Option A
  4. Quick Check:

    Clear summary + detailed why = best commit message [OK]
Hint: Use clear summary and explain why change matters [OK]
Common Mistakes:
  • Using vague summaries
  • Wrong verbs like 'Fix' for new features
  • Too short or unclear explanations