Skip to content

commandGit and releases

Squash Commits

Turns a messy branch history into a few clear commits with proper messages, showing the plan before rewriting anything.

npx workspacetemplates add squash-commits --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/squash-commits.md15 lines · 1.2 KBFile
---
description: Turns a messy branch history into a few clear commits with proper messages, showing the plan before rewriting anything.
argument-hint: "[base branch, or \"single commit\"]"
---

Squash the commits on this branch. Instructions: $ARGUMENTS (for example the base branch or "single commit").

1. Find the base: `git merge-base HEAD <base>` with the given base or the default branch. Show `git log --oneline <base>..HEAD` and `git diff --stat <base>..HEAD`.
2. If any of these commits exist on a shared remote branch that others may use, warn and ask before continuing.
3. Propose groups: related commits by files and purpose, ordered so each group builds and passes tests alone. Give each a message in the project's style (check recent `git log -n 10 --oneline`), with a body explaining why.
4. Print the plan: new commit message, commits folded into it, files.
5. Create a backup: `git branch backup/<branch>-<date>`.
6. After approval, rewrite without interactive tools: `git reset --soft <base>` then commit each group by staging its files, or a scripted `git rebase`. Verify `git diff backup/<branch>` is empty.

Report the new log and the backup name. Do not push; mention that `--force-with-lease` is required if already pushed.

What it does

Work in progress leaves commits named "fix" or "again" that make review and later debugging harder. This command groups the commits on your branch into logical units and drafts a message for each.

It shows the plan and a backup point first, rewrites only after your yes, and warns you before touching commits that other people may already have.

Example

you › /squash-commits main

agent › 11 commits since main. Plan:
1. feat(search): add fuzzy matching (6 commits)
2. test(search): cover empty and unicode queries (3)
3. docs: describe search flags (2)
Backup: backup/search-1115. Proceed?
After yes: new log shown, diff against backup is empty.

Questions

Can I get back the old history?
Yes. A backup branch is created before any rewrite, and the final check proves the result matches it exactly.
Does it force push?
Never. It tells you when a force push with lease is needed and leaves that to you.
  • Branch Cleanup

    CommandGit and releases

    Free
  • Changelog Entry

    CommandGit and releases

    Free
  • Cherry Pick Fix

    CommandGit and releases

    Free
  • Commit Message

    CommandGit and releases

    Free