Atomic Commits
Organize multiple git changes into clean, atomic commits that maintain a proper git history.
Workflow
1. Analyze Changes
git status
git diff --stat
git diff
2. Group Changes Logically
Categorize by type:
- feat: New features
- fix: Bug fixes
- refactor: Code improvements
- docs: Documentation
- test: Test changes
- chore: Maintenance
3. Commit Incrementally
Stage specific files for each logical commit:
git add path/to/related/files
git commit -m "feat: add user authentication"
git add path/to/other/files
git commit -m "fix: correct null check in validator"
4. Push
git log --oneline -10 # Verify commits
git push origin <branch>
Commit Order
- Documentation (lowest risk)
- Tests (verification setup)
- Bug fixes (independent corrections)
- Features (main changes)
- Refactoring (improvements)
Commit Message Format
<type>(<scope>): <description>
[optional body]
Types: feat, fix, docs, style, refactor, test, chore
Example
Given changes to login page, avatar fix, README update, and new tests:
git add README.md
git commit -m "docs: update README with login instructions"
git add tests/login.test.ts
git commit -m "test: add login component tests"
git add src/components/Avatar.tsx
git commit -m "fix: correct avatar display on retina screens"
git add src/pages/Login.tsx src/components/LoginForm.tsx
git commit -m "feat: add login page with validation"
git push origin feature/login
Tips
- Each commit should be independently reviewable
- Each commit should leave codebase in working state
- When in doubt, prefer more commits over fewer
- Use
git add -pfor interactive staging of partial files
See references/advanced.md for advanced patterns.