$npx -y skills add PaulRBerg/agent-skills --skill git-squashSquash a feature branch into one commit via soft reset to the merge base, ready for a clean PR.
| 1 | # Git Squash |
| 2 | |
| 3 | Squash the current feature branch into one commit representing its net change relative to the resolved default branch. |
| 4 | |
| 5 | ## Arguments |
| 6 | |
| 7 | - `--subject <line>`: require this exact first line in the replacement commit message. |
| 8 | - `--base <branch>`: override default-branch detection. |
| 9 | |
| 10 | Without `--subject`, the agent writes a conventional-commit subject from the surviving net diff. Without `--base`, the |
| 11 | helper resolves `origin/HEAD`, then origin's advertised head, then local/remote `main`, `master`, or `trunk`. |
| 12 | |
| 13 | ## Plan Interface |
| 14 | |
| 15 | Resolve the helper from this `SKILL.md`. Write its JSON to a scratch path outside the repository so preflight remains |
| 16 | clean: |
| 17 | |
| 18 | ```sh |
| 19 | uv run "<skill-dir>/scripts/git-squash.py" plan \ |
| 20 | [--cwd <repo>] [--base <branch>] [--subject <line>] > <plan.json> |
| 21 | ``` |
| 22 | |
| 23 | `plan` is read-only. It verifies the Git worktree, attached branch, clean tree/index, resolved base, non-default current |
| 24 | branch, merge base, positive ahead count, and remote facts. It returns `schemaVersion: 1`, the immutable original HEAD, |
| 25 | merge base, base ref, commits in chronological order, unique authors, tree/remote state, and rollback facts. A failed |
| 26 | precondition exits without changing history. |
| 27 | |
| 28 | Show the branch, base ref, merge base, commits replaced, tree state, remote state, and rollback HEAD in a compact plain |
| 29 | table before mutation. |
| 30 | |
| 31 | ## Agent-Owned Commit Message |
| 32 | |
| 33 | Inspect the plan's commits and the net diff from `mergeBase..originalHead`. The net diff is authoritative; intermediate |
| 34 | commits supply intent and attribution only. Inspect targeted hunks when the summary is ambiguous. |
| 35 | |
| 36 | Use `--subject` exactly when supplied. Otherwise choose the conventional type from the surviving outcome: `feat`, `fix`, |
| 37 | `refactor`, `docs`, `test`, `build`, `ci`, `chore(deps)`, `style`, `perf`, `ai`, or `chore`. Do not call the change |
| 38 | `chore` merely because it is a squash. |
| 39 | |
| 40 | Keep the subject imperative, lowercase after the prefix, specific, and without a trailing period. Add at most five body |
| 41 | bullets for distinct surviving outcomes; omit the body when the subject is sufficient. Do not dump paths or statistics. |
| 42 | Append one `Co-authored-by: Name <email>` trailer for each plan author other than the current Git user. The agent owns |
| 43 | all semantic wording and must ensure every statement is supported by the net diff. |
| 44 | |
| 45 | Write the final message to a scratch file outside the repository. |
| 46 | |
| 47 | ## Apply Interface |
| 48 | |
| 49 | ```sh |
| 50 | uv run "<skill-dir>/scripts/git-squash.py" apply \ |
| 51 | --plan <plan.json> --message-file <message.txt> |
| 52 | ``` |
| 53 | |
| 54 | `apply` binds the rewrite to the plan's original HEAD, branch, merge base, base ref, clean state, rollback index, and |
| 55 | optional subject. It revalidates them immediately before mutation; a stale plan fails without changing history. It |
| 56 | soft-resets to the merge base, verifies the staged net diff is non-empty, and commits from the message file. |
| 57 | |
| 58 | If any operation fails after mutation but before the replacement commit completes, the helper restores the original HEAD |
| 59 | and exact index. It leaves working-tree files untouched. Do not reproduce the reset/rollback sequence manually or |
| 60 | continue after a helper failure without inspecting its diagnostic and current Git state. |
| 61 | |
| 62 | ## Report |
| 63 | |
| 64 | On success, report the plan's replaced count, resolved base ref, new hash, and subject. If the branch exists on origin, |
| 65 | state the exact next action `git push --force-with-lease`; do not run it unless explicitly requested. |
| 66 | |
| 67 | Lead with `### ✅ Squashed — <old count> commits → 1`. Keep preflight facts, hashes, commands, errors, and rollback |
| 68 | wording plain and exact. |