Split a large commit into smaller, logical commits
✓Works with OpenClaudeYou are a Git expert specializing in commit history management. The user wants to split a large commit into smaller, logical commits while preserving history and maintaining a clean git log.
What to check first
- Run
git log --oneline -n 5to see recent commits and identify the target commit hash - Run
git show <commit-hash>to view the full diff of the commit you're splitting - Run
git statusto ensure your working tree is clean before starting - Check if you're on the correct branch with
git branch
Steps
- Start an interactive rebase targeting the commit before the one you want to split. Use
git rebase -i <parent-commit-hash>(orgit rebase -i HEAD~nwhere n is the number of commits back) - In the editor that opens, find the line with your target commit and change
picktoedit, then save and exit - Git will pause at that commit. Run
git reset HEAD~1to unstage all changes from that commit while keeping them in your working directory - Verify all changes are unstaged with
git status— you should see all modified/untracked files listed as "Changes not staged" - Stage specific files or hunks for the first logical commit using
git add <file>orgit add -pfor interactive hunk selection - Create the first commit with
git commit -m "Clear, specific commit message for logical chunk 1" - Repeat steps 5-6 for remaining logical chunks: stage the next related changes with
git addand commit with a descriptive message - After all smaller commits are created, run
git rebase --continueto finish the interactive rebase and apply any remaining commits
Code
#!/bin/bash
# Split a large commit into multiple logical commits
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get the commit hash to split (default: HEAD, or pass as argument)
TARGET_COMMIT="${1:-HEAD}"
# Resolve to full hash
COMMIT_HASH=$(git rev-parse "$TARGET_COMMIT")
PARENT_HASH=$(git rev-parse "$COMMIT_HASH~1")
echo -e "${YELLOW}Target commit: $COMMIT_HASH${NC}"
echo -e "${YELLOW}Parent commit: $PARENT_HASH${NC}"
# Verify clean working directory
if ! git diff-index --quiet HEAD --; then
echo -e "${RED}Error: Working directory is not clean${NC}"
exit 1
fi
# Start interactive rebase
echo -e "${YELLOW}Starting interactive rebase...${NC}"
GIT_SEQUENCE_EDITOR="sed -i '0,/pick $COMMIT_HASH/{s/pick $COMMIT_HASH/edit $COMMIT_HASH/;}'" \
git rebase -i
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Git & Version Control Skills
Other Claude Code skills in the same category — free to download.
Smart Commit
Generate conventional commit messages by analyzing staged changes
Branch Cleanup
Find and delete merged/stale local and remote branches
Git Undo
Safely undo the last git operation (commit, merge, rebase, etc.)
Changelog Generator
Generate CHANGELOG.md from git history using conventional commits
Conflict Resolver
Analyze and suggest resolutions for merge conflicts
Git Bisect Helper
Automate git bisect to find the commit that introduced a bug
PR Description
Generate detailed PR descriptions from branch diff
Git Hooks Setup
Set up pre-commit, pre-push, and commit-msg hooks
Want a Git & Version Control skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.