Home
cd ../playbooks
Developer ToolsIntermediate

Reshape PR Commits

Turn a branch's messy WIP/fixup commit history into a clean, logically-grouped set of commits before review — proposed regrouping with explicit approval, git reset --soft plus staged re-commits instead of interactive rebase, and hard guardrails (feature branches only, force-with-lease only, never touch another author's commits).

5 minutes
By Qualcomm (GenieX)Source
#git#pull-requests#commit-history#code-review#git-workflow

A PR with fifteen commits named 'wip', 'fix', and 'oops typo' works fine to merge, but it makes the diff impossible to review commit-by-commit and turns git blame into archaeology — and the fix isn't interactive rebase's fragile editor dance, it's a three-command reset-and-recommit flow any agent can run safely with the right guardrails.

Who it's for: developers who batch small WIP commits while working and need a clean history before opening a PR, tech leads who want reviewable, logically-grouped diffs instead of a stream-of-consciousness commit log, teams standardizing on conventional commit messages before merge, anyone nervous about force-pushing history rewrites

Example

"Clean up my commits before I open this PR" → git log against the merge-base to see the noisy history, the combined diff read to understand what actually changed (not what the messages claim), a numbered regrouping plan presented for approval before anything is touched, then git reset --soft plus staged re-commits and a force-with-lease push

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

# Reshape PR Commits

Turn the current branch's commit history into a set of commits that each represent one coherent logical change, with terse messages. Use when asked to tidy, squash, reshape, or clean up commits on the current branch or PR.

## Proactive Suggestion (When Not Explicitly Invoked)

When the user signals the PR is done — "done with this PR," "ready for review," "let's open the PR," or just before calling a PR-ready command — check `git log <base>..HEAD --oneline`. If the history is noisy (WIP/fixup/"oops" commits, or many tiny commits touching the same area), offer once: suggest cleaning up the commits before review. Accept either answer and move on; do not re-ask in the same session.

## Non-Negotiable Guardrails

- **Only ever rewrite the current feature branch.** Refuse if the branch is the main/default branch, or if the current HEAD is already merged.
- **Always `--force-with-lease`**, never plain `--force`, when pushing the rewritten history.
- Before touching history, surface the proposed final shape (one line per planned commit) and get explicit user approval.
- If the branch has commits from other authors, stop and ask — do not silently re-author someone else's work.

## Flow

1. **Identify the base.** `git merge-base HEAD origin/main` (or whatever branch the PR targets). Show `git log --oneline <base>..HEAD`.
2. **Read the combined diff.** `git diff <base>..HEAD` — understand what actually changed, not just what the existing commit messages claim.
3. **Propose a regrouping.** Rules:
   - One commit per logical change. Unrelated files go in separate commits.
   - Pure refactor and behavior change don't mix in the same commit.
   - Test additions usually ride with the code they test, unless the user is landing tests separately on purpose.
4. **Present the plan** as a numbered list — `<type>(<scope>): <subject>` plus an optional one-line rationale for why that split exists. Wait for approval before touching anything.
5. **Execute with `git reset --soft <base>`**, followed by staged `git add` + `git commit` per group. Prefer this over interactive rebase — it's simpler, produces fewer merge conflicts, and skips the editor dance entirely.
6. **Push with `git push --force-with-lease`.**

## Commit Message Rules

Follow the project's own commit-message conventions (type prefix, scope, subject style, body policy) if a `CONTRIBUTING.md` or similar document defines them. Don't invent a scheme that conflicts with an existing house style.

## When in Doubt

If the user's intent for the split is ambiguous — "clean this up" against fifteen mixed commits — ask one clarifying question before proposing the plan. Don't guess at ten different groupings and hope one lands.

Get new playbooks like this one

One email a week with new Claude Code workflows. Free, like everything here.

No spam. Unsubscribe anytime.

README.md

What This Does

A disciplined workflow for turning a noisy feature-branch history into a small set of commits, each representing one coherent logical change, before a PR goes up for review. Rather than interactive rebase's fragile pick/squash/reword editor flow, it uses git reset --soft back to the merge-base followed by staged git add + git commit per logical group — simpler, with far fewer merge-conflict surprises. The flow always reads the combined diff first (not just the existing commit messages, which are often wrong or stale) before proposing a regrouping, then presents the planned final shape as a numbered list and waits for explicit approval before touching any history.

It also defines when to offer this proactively: when the user signals a PR is ready ("done with this PR," "let's open it") and the commit log looks like a stream of WIP/fixup commits, suggest the cleanup once — but never insist, and never re-ask in the same session if declined. The guardrails are the load-bearing part: only ever rewrite the current feature branch (refuse on main or an already-merged HEAD), always --force-with-lease on the push, and stop and ask rather than silently re-authoring history if another author's commits are mixed in.


Quick Start

Step 1: Create a Project Folder

mkdir reshape-commits && cd reshape-commits

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ./

Step 3: Clean Up a Branch

claude

Ask Claude to clean up the commits on your current feature branch before you open (or update) a PR. It will read the base and the full diff, propose a numbered regrouping for your approval, then reset and re-commit — never force-pushing without --force-with-lease and never touching main.


Tips & Best Practices

  • Always let it show the proposed final commit list before executing — a one-line rationale per group makes it easy to catch a wrong split (e.g., a refactor accidentally bundled with a behavior change) before it's baked into history.
  • If your project has a CONTRIBUTING.md with commit-message conventions (type prefixes, scope names, subject rules), point to it — the reshaping should match the house style rather than invent its own.
  • git reset --soft plus staged re-commits is deliberately preferred over interactive rebase here: no editor to drive, no pick/squash lines to get wrong, and conflicts only ever show up once, at the final push.

Limitations

  • Rewrites history — only ever safe on a feature branch that hasn't been merged and that no one else is actively building on top of; the guardrails refuse main and already-merged branches, but a shared feature branch with other active contributors still needs care.
  • Refuses to touch commits authored by someone else without asking first — on a branch with mixed authorship, expect it to stop and check rather than silently reshape everyone's history.
  • Assumes a single target base branch (typically main); a more complex branching model (stacked PRs, multiple integration branches) needs the base identified manually before the flow starts.

$Related Playbooks

Developer Tools

Simplicity First Code Gate

A hard correctness gate against over-complex or oversized code — one ordering principle (human readability first, agent traceability second), five enforceable rules, and a pre-finish checklist that treats unnecessary complexity as a bug, not a style opinion.

2 minutes
Beginner
Developer Tools

Slidev Presentation Builder

Build developer-focused presentations with Slidev — Markdown-driven slides with live code, syntax highlighting, Monaco editor embeds, Mermaid/PlantUML diagrams, LaTeX math, click-based animations, and presenter notes, plus a quick-reference table for the exact syntax each feature needs.

5 minutes
Beginner
Developer Tools

Technical Writing Style Guide

Write docstrings, READMEs, commit messages, and PR descriptions that read like human technical documentation instead of LLM output — six concrete 'tells' with before/after rewrites, a smoothness diagnostic for prose that sounds authoritative while stating one fact three times, and industry-metaphor substitution tables ('surfaces' to 'raises/returns/logs', 'wired through' to 'passed as a parameter').

5 minutes
Intermediate
Developer Tools

Secret Scan and Rotation

Find committed credentials in a repository's working tree and full history, triage real secrets from test fixtures, and drive rotation-first remediation — with an absolute rule against ever printing a secret's actual value, even during the scan itself.

5 minutes
Intermediate
Developer Tools

Self-Improvement Loop Design

Design systems where the harness itself is the optimization target — an optimization ladder from prompt to context to workflow to harness code, a two-split empirical acceptance gate, an outside-the-loop invariant for the evaluator, and a catalog of documented reward-hacking and collapse failure modes.

10 minutes
Advanced
Developer Tools

Skill Security Inspector

Review an AI agent skill before installing it using two independent lines — static scanner evidence plus source-aware semantic judgment — checking purpose fit, permission fit, sensitive access, external transmission, execution risk, and persistence, down to a clear APPROVE, CAUTION, or REJECT verdict.

10 minutes
Intermediate
Developer Tools

Semantic Prompt Compression

Re-encode verbose system prompts, tool descriptions, and skill bodies into a dense telegraphic register — punctuation as connectives, label frames, verbless assertions — via re-encoding, not word deletion, with a density gate and a declared-loss verification pass.

5 minutes
Advanced
Developer Tools

Simplified Technical English for Docs

Write or rewrite technical documentation with the ASD-STE100 Simplified Technical English discipline — the aerospace maintenance-manual standard adapted for READMEs, runbooks, error messages, incident reports, and agent instructions.

10 minutes
Intermediate
Developer Tools

Subagent-Driven Development

Execute an implementation plan by dispatching a fresh subagent per task with a spec-and-quality review after each, a ledger that survives compaction, and a 'rulings not stalls' policy that keeps a running plan from waiting on a human at every fork.

10 minutes
Advanced
Developer Tools

Secure Coding Practices

A threat-model-first secure coding reference — trust-boundary mapping, a STRIDE quick-pass, a three-tier always/ask-first/never boundary system, and copy-paste prevention patterns for injection, XSS, broken access control, and SSRF.

10 minutes
Intermediate
Developer Tools

Security Guidance Review

Three-layer continuous security review for AI-generated code — instant regex warnings on edit, an LLM diff review at end of turn, and an agentic commit-time reviewer that traces data flow across files.

10 minutes
Advanced
Developer Tools

Shannon: Autonomous Pentesting for Your Own Apps

An operating guide for driving Keygraph's Shannon CLI: scope a white-box pentest against an app you own, run it, and turn the proven findings into fix tasks

15 minutes
Advanced

Browse all Developer Tools playbooks →