Overview
This guide will demonstrate how to commit staged files using both Lazygit and basic terminal commands. Understanding how to commit changes effectively is key to maintaining a well-organized and clear project history.
Lazygit
Committing Changes
After staging your content, follow these steps to commit:
-
Access Files Panel
- Press
2
to navigate to the 2. Files panel.
- Press
-
Commit Options
c
: Commit the staged changes directly.C
: Open your$EDITOR
to write a more detailed commit message.w
: Commit without running pre-commit hooks.
-
Write Commit Message
- Subject Line: The first line (up to 50 characters) should summarize the commit’s content.
- Body: The second line and beyond provide details about the commit’s purpose and reasoning.
- Use
tab
to switch between the subject and body sections. - See also: Writing a Good Commit Message
-
Finalize Commit
- Press
enter
to complete the commit process.
- Press
-
Verify Commit
- The new commit will appear in the 4. Commits panel, highlighted in a distinct color to indicate its local status and pending push to remote.
Note on Commit Messages
- A well-crafted commit message is vital for understanding the context and rationale behind each change.
Basic Terminal
Committing via Terminal
For terminal-based commits, you have two main options:
-
Inline Commit Message
- Use this for quick commits:
- Replace “commit message” with a concise description of your changes.
-
Detailed Commit via
$EDITOR
- For more detailed messages, default to your configured editor:
- This opens your
$EDITOR
where you can write a structured message with a subject and detailed body.
Conclusion
Committing changes, whether through Lazygit or the terminal, is a fundamental aspect of version control. It allows for tracking changes over time and understanding the history of your project. Practice these methods to enhance your version control proficiency.