Squash git commits by pattern or hash without opening an editor
Squashes git commits by pattern, hash, or range without opening an editor.
/plugin marketplace add bengous/claude-code-plugins/plugin install git-tools@bengous-plugins--pattern <regex> | --hashes <h1,h2,...> | --range <N> [--backup] [--dry-run]Squash git commits interactively without vim. Supports pattern matching, specific hashes, or simple ranges.
$ARGUMENTS
# Squash all commits matching a pattern (e.g., "shellcheck", "fix:", "WIP")
/squash --pattern "shellcheck"
# Squash specific commits by hash
/squash --hashes "abc123,def456,ghi789"
# Squash last N commits (simple case, all contiguous)
/squash --range 5
# Add --backup to create backup branch automatically
/squash --pattern "refactor" --backup
# Dry run to preview (no changes)
/squash --pattern "test" --dry-run
GIT_SEQUENCE_EDITOR (no vim!)Pattern mode:
Hashes mode:
Range mode:
git reset --soft HEAD~N + new commitParse the arguments and execute the appropriate strategy:
For --range N:
# Create backup if requested
git branch backup-$(date +%s) HEAD
# Soft reset and recommit
git reset --soft HEAD~N
git commit -m "Squashed N commits"
For --pattern or --hashes:
# 1. List commits to find matches
git log --oneline HEAD~50..HEAD
# 2. Find the base commit (oldest matching)
# 3. Generate a sed script that changes "pick" to "squash" for target commits
# 4. Execute: GIT_SEQUENCE_EDITOR="sed -i '<script>'" git rebase -i <base>^
Always:
git status --porcelain