Git & Version Controladvanced
Split a large commit into smaller, logical commits
Commit Splitter
Split a large commit into smaller, logical commits
Split a large commit into smaller, logical commits.
Instructions
- First, undo the large commit but keep changes:
git reset --soft HEAD~1 # if it's the latest commit
# or
git reset --soft <commit> # for a specific commit
- View all staged changes:
git diff --staged --stat # overview
git diff --staged # details
-
Identify logical groups:
- Separate refactoring from feature changes
- Separate test additions from implementation
- Separate dependency updates from code changes
- Separate formatting from logic changes
-
Unstage everything, then add back in groups:
git reset HEAD . # unstage all
git add src/auth/login.ts src/auth/types.ts # group 1: auth logic
git commit -m "feat(auth): add login endpoint"
git add tests/auth/ # group 2: tests
git commit -m "test(auth): add login tests"
git add package.json package-lock.json # group 3: deps
git commit -m "chore: add bcrypt dependency"
- For partial file staging:
git add -p filename # interactive hunk selection
Rules
- Each commit should build and pass tests independently
- Each commit should have a clear, single purpose