Basics
Git Comments
Adding Commit Messages
Git commit messages use -m for clear change descriptions.
Understanding Git Commit Messages
Git commit messages are an essential part of version control, providing a clear and concise description of changes made to the codebase. Good commit messages help collaborators understand the context of changes without diving into the code itself.
Creating a Git Commit Message with -m
To create a Git commit message, you can use the -m
option followed by a message in quotes. This inline method is efficient for quick commits.
Best Practices for Writing Commit Messages
Here are some best practices for writing effective commit messages:
- Be concise: Keep messages short but descriptive.
- Use the imperative mood: Start messages with a verb, e.g., 'Add', 'Fix', 'Refactor'.
- Explain why: When necessary, include the reason behind a change.
- Separate subject from body: If more detail is needed, separate the summary and description with a blank line.
Multi-line Commit Messages
For more detailed commit messages, omit the -m
flag and use your default text editor to write a subject and body. This method is useful for complex changes that require thorough explanations.
Examples of Good Commit Messages
Let's take a look at some examples of well-written commit messages:
git commit -m "Fix bug in user login process"
- Clearly states the action and the area affected.git commit -m "Add unit tests for payment module"
- Describes the addition of tests.git commit
followed by a detailed message:Refactor database schema
Improve indexing and normalize table structures for better performance.