Multiline Git commit messages are used to provide more context and detail beyond a short summary. They are particularly useful in collaborative projects and when changes are non-trivial.
Structure
- Subject Line: A brief summary of the change (max ~50 characters).
- Blank Line: A blank line between the subject and body is required.
- Body: A more detailed explanation (wrapped at ~72 characters per line is common).
- Footer (optional): Tags like
Fixes:
,Refs:
, orReviewed-by:
.
Example 1: Prevent racing of requests
fix: prevent racing of requests Introduce a request id and a reference to latest request. Dismiss incoming responses other than from latest request. Remove timeouts which were used to mitigate the racing issue but are obsolete now. Reviewed-by: Z Refs: #123
Example 2: Add retry logic to network requests
feat: add retry logic for network requests Retries failed HTTP requests up to 3 times with exponential backoff. Handles temporary network errors more gracefully. Ref: #234 Reviewed-by: Alice <alice@example.com>
Example 3: Refactor authentication system
refactor: simplify authentication flow The login process has been updated to use the new session management API. This makes the code cleaner and more testable. Legacy token code was removed. BREAKING CHANGE: old `AuthToken` API is no longer supported. Reviewed-by: Bob
Example 4: Fix crash on empty input
fix: crash when input is empty Guarded against null or empty values in the parser, which previously caused a segmentation fault under certain edge cases. Fixes: #89
How to Write Multiline Commit Messages
You can write multiline commit messages using:
git commit # Then your editor will open. Write subject, body, and footer there.
Or from the command line with -m
used multiple times:
git commit -m "fix: crash when input is empty" \ -m "Guarded against null or empty values..." \ -m "Fixes: #89"
Tips
- Be concise but informative.
- Use imperative mood (e.g., "Fix bug", not "Fixed bug").
- Use bullet points or paragraphs for longer explanations.
- Always leave the second line blank after the subject line.