git commit
Record staged changes as a permanent snapshot in history
Practical Example
git add . git commit -m "Fix login validation error" # Creates commit abc1234 with author, date, and message
Command Overview & How It Works
Takes all currently staged changes and creates a permanent snapshot with a unique SHA-1 hash, author metadata, timestamp, and commit message. A well-written commit message follows the conventional format: a short summary line (50 chars or fewer), a blank line, then a longer body explaining what and why. Use git commit -m "message" for a quick inline message, or just git commit to open your configured editor for a detailed message. Use git commit --amend to modify the most recent commit (message, content, or both) — useful for fixing typos or forgetting to stage a file. Use git commit -a to automatically stage all tracked files before committing, bypassing the separate git add step. Every commit is immutable — once created, its history should not be rewritten on shared branches.
Practical Tips
- •Keep the subject line under 50 characters and use the imperative mood: 'Fix bug', not 'Fixed bug'.
- •Use git commit --amend to fix the message or add a forgotten file to your most recent commit — before pushing it.
- •Write a body after a blank line explaining the 'why'; the diff already shows the 'what'.