Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Git & Version Controladvanced

Commit Splitter

Share

Split a large commit into smaller, logical commits

Works with OpenClaude

You 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 5 to 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 status to ensure your working tree is clean before starting
  • Check if you're on the correct branch with git branch

Steps

  1. Start an interactive rebase targeting the commit before the one you want to split. Use git rebase -i <parent-commit-hash> (or git rebase -i HEAD~n where n is the number of commits back)
  2. In the editor that opens, find the line with your target commit and change pick to edit, then save and exit
  3. Git will pause at that commit. Run git reset HEAD~1 to unstage all changes from that commit while keeping them in your working directory
  4. Verify all changes are unstaged with git status — you should see all modified/untracked files listed as "Changes not staged"
  5. Stage specific files or hunks for the first logical commit using git add <file> or git add -p for interactive hunk selection
  6. Create the first commit with git commit -m "Clear, specific commit message for logical chunk 1"
  7. Repeat steps 5-6 for remaining logical chunks: stage the next related changes with git add and commit with a descriptive message
  8. After all smaller commits are created, run git rebase --continue to 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

Quick Info

Difficultyadvanced
Version1.0.0
AuthorClaude Skills Hub
gitcommitrefactoring

Install command:

curl -o ~/.claude/skills/commit-splitter.md https://claude-skills-hub.vercel.app/skills/git/commit-splitter.md

Related Git & Version Control Skills

Other Claude Code skills in the same category — free to download.

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.