Creating Commits
The git commit command saves your staged changes as a new snapshot in the repository history.
What is a Commit?
A commit is a snapshot of your project that includes:
- All staged changes
- A unique SHA-1 hash (ID)
- Author name and email
- Timestamp
- Commit message
- Pointer to parent commit(s)
Basic Commit
Commit Commands
Commit with Message
git commit -m "Add new feature"
Add and Commit Together
git commit -am "Fix bug in login"
Note: This only works for already-tracked files.
Commit with Detailed Message
git commit
This opens your editor for a longer message.
Writing Good Commit Messages
Format
Short summary (50 chars or less)
More detailed explanation if needed. Wrap at 72 characters.
Explain the problem this commit solves.
- Bullet points are okay
- Use present tense: "Add feature" not "Added feature"
Examples
Good:
Add user authenticationFix memory leak in image processingUpdate README with installation steps
Bad:
Fixed stuffWIPChanges
Amending Commits
Fix the last commit:
git commit --amend -m "New message"
Add forgotten files to last commit:
git add forgotten-file.txt
git commit --amend --no-edit
Viewing Commit Details
git show HEAD
git show abc1234
Exercise: Create a Commit
Stage any changes and create a commit with a message:

