[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BR6MWG9Z08BVSC8ZQCTCK2":3,"skill-same:01M7BR6MWG9Z08BVSC8ZQCTCK2":52},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M7BR6MWG9Z08BVSC8ZQCTCK2","rewrite-pr-history",null,"Use when deliberately editing the history of an open PR's branch: dropping, reordering, splitting or rewording commits, or squashing before review. Fire on \"remove the X commit from PR N\", \"reorder the commits\", \"drop the last commit\", \"clean up the history before review\". For the routine post-merge rebase of open PRs (duplicate commits after a parent landed), use branch-hygiene instead, that is mechanical cleanup, this is surgery.","damson\u002Fhard-won-skills","damson","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F804217?v=4","01M7BR01SMVEGA4HRD46VV1SXF","Damien D.","01M7BR01TR37MB9R73C1C0ENGG",1,"MIT","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fgit-workflow\u002Fskills\u002Frewrite-pr-history\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: rewrite-pr-history\ndescription: >\n  Use when deliberately editing the history of an open PR's branch: dropping, reordering,\n  splitting or rewording commits, or squashing before review. Fire on \"remove the X commit\n  from PR N\", \"reorder the commits\", \"drop the last commit\", \"clean up the history before\n  review\". For the routine post-merge rebase of open PRs (duplicate commits after a parent\n  landed), use branch-hygiene instead, that is mechanical cleanup, this is surgery.\n---\n\n# Rewrite PR history\n\nThe goal: never lose the user's work, never force-push a shared branch, and\nshow the plan before rewriting. Every step is recoverable if interrupted.\n\n## Procedure\n\n### 1. Read PR state\n\n```bash\ngh pr view \u003CN> --json baseRefName,headRefName,mergeable,mergeStateStatus,reviewDecision,commits\n```\n\nConfirm:\n- Head branch is **not** `main`, `master`, `develop`, or any protected branch.\n- The branch is yours to rewrite. Checked, not assumed: only you appear in `git\n  shortlog -sn origin\u002F\u003Cbase>..HEAD`, and only one open PR has this head (`gh pr\n  list --head \u003Cbranch>`). Either check failing means the branch may be shared:\n  ask before rewriting; a rewrite under someone else's feet loses their work.\n- If `reviewDecision` shows pending or approved reviews, surface that: review\n  comments anchor to commits and go stale after a rewrite. Ask before\n  continuing.\n\n### 2. Sync working tree\n\n```bash\ngit fetch origin --prune\ngit checkout \u003Chead-branch>\n```\n\nVerify clean working tree (`git status -s` returns empty). If dirty, stop and\nask the user. Never auto-stash without consent.\n\n### 3. Show the plan\n\nRun `git log --oneline origin\u002F\u003Cbase>..HEAD` and `git diff origin\u002F\u003Cbase> --stat`.\nState the intended action in plain words (e.g. \"I'll drop commit X by rebasing\n--onto origin\u002Fmain starting after it\"). **Wait for explicit user \"go\"** before\nrewriting.\n\n### 4. Rewrite\n\nUse the smallest-blast-radius command for the job:\n\n| Goal | Command |\n|---|---|\n| Resolve conflicts with new main | `git rebase origin\u002Fmain` |\n| Drop one commit in the middle | `git rebase --onto \u003Cbase> \u003Ccommit-to-drop> \u003Cbranch>` |\n| Reorder \u002F squash | non-interactive sequence edit, below: `git rebase -i` needs a terminal this environment does not have |\n| Reword last commit only | `git commit --amend` (verify HEAD is the right commit first) |\n| Split last commit | `git reset --soft HEAD~` then re-stage in parts |\n\nNon-interactive drop\u002Freorder: pipe the todo-list edit through the sequence\neditor rather than a terminal: `GIT_SEQUENCE_EDITOR=\u003Cscript> git rebase -i\n\u003Cbase>`, where the script edits `\"${1}\"` in place. Write the edit to a temporary\nfile and move it over the original rather than reaching for `sed -i`: the\nin-place flag takes a mandatory empty argument on BSD (`sed -i ''`) and refuses\none on GNU, so either spelling is broken on half the machines that install this\nskill.\n\nResolve the commit to a real object id first, and export it: git writes object\nids in the todo file, so a literal `\u003Csha>` matches nothing and the rebase\nreplays the branch unchanged, which looks like success.\n\n```bash\nexport DROP=$(git rev-parse --short=7 \u003Ccommit-to-drop>)\nGIT_SEQUENCE_EDITOR='f() { sed \"s\u002F^pick $DROP\u002Fdrop $DROP\u002F\" \"${1}\" > \"${1}.todo\" && mv \"${1}.todo\" \"${1}\"; }; f' \\\n  git rebase -i \u003Cbase>\n```\n\nSeven characters on purpose: git abbreviates the todo's ids to whatever the\nrepository needs, and a seven-character prefix still matches a longer one, while\na full forty-character id matches nothing at all.\n\n**If the rebase stops on a conflict**: resolve the conflicted files, `git add`\nthem, `git rebase --continue`; repeat per commit. If a resolution is not\nobviously right, `git rebase --abort` returns the branch to its pre-rebase\nstate and the question goes to the user: an aborted rebase loses nothing.\n\nRe-verify with `git log --oneline origin\u002F\u003Cbase>..HEAD` and `git diff\norigin\u002F\u003Cbase> --stat` after every step, and confirm `git diff HEAD` is empty: a\nnon-empty diff there means something outside the rebase (an editor with the\nfile open, a merge tool) rewrote the working tree, and committing would\nsilently fold that change in.\n\n### 5. Local checks before pushing\n\nRun the project's documented test command. Detect it, never assume a toolchain:\na `test` \u002F `check` \u002F `verify` recipe in `just --list`, else `scripts.test` in\n`package.json`, else a `test` target in the `Makefile`, else the language\ndefault (`bats tests\u002F`, `pytest`, `cargo test`, `go test .\u002F...`). Also run the\nlinter the repo's CI uses (read `.github\u002Fworkflows\u002F` for hints); if no lint\nstep is discoverable in the CI config or the task runner, skip linting and say\nso in the report. Never stall on the search. Don't push if checks fail: fix\nlocally first.\n\n### 6. Force-push with lease\n\n```bash\ngit push --force-with-lease origin \u003Cbranch>\n```\n\n**Never** plain `--force`. `--force-with-lease` refuses to clobber if the\nremote moved since the last fetch: if it rejects, stop and surface the diff\nbetween expected and actual remote state.\n\n### 7. Verify on the platform\n\n```bash\ngh pr view \u003CN> --json mergeable,mergeStateStatus,commits -q \\\n  '{state:.mergeStateStatus,mergeable:.mergeable,commits:[.commits[].messageHeadline]}'\n```\n\nConfirm `mergeable: MERGEABLE`, `mergeStateStatus: CLEAN` (or `UNSTABLE` while\nCI runs), and that the commit list matches the planned outcome. Report back.\n\n## When to STOP\n\n- **Branch is `main` or shared** → refuse. Suggest a revert PR or a forward-fix.\n- **`--force-with-lease` is rejected** by the remote → stop, surface the diff,\n  ask. Do not switch to plain `--force`.\n- **No explicit per-branch authorization for the force-push** → ask. Prior\n  authorization on one branch does not extend to another.\n- **PR has approved reviews or unresolved comments** → ask before rewriting;\n  reviewers may need to re-approve.\n- **CI was green and the rewrite is purely cosmetic** → ask whether it is worth\n  invalidating the run; sometimes a follow-up commit is better.\n- **Working tree is dirty** → ask the user. Never silently stash.\n","# Rewrite PR history\n\nThe goal: never lose the user's work, never force-push a shared branch, and\nshow the plan before rewriting. Every step is recoverable if interrupted.\n\n## Procedure\n\n### 1. Read PR state\n\n```bash\ngh pr view \u003CN> --json baseRefName,headRefName,mergeable,mergeStateStatus,reviewDecision,commits\n```\n\nConfirm:\n- Head branch is **not** `main`, `master`, `develop`, or any protected branch.\n- The branch is yours to rewrite. Checked, not assumed: only you appear in `git\n  shortlog -sn origin\u002F\u003Cbase>..HEAD`, and only one open PR has this head (`gh pr\n  list --head \u003Cbranch>`). Either check failing means the branch may be shared:\n  ask before rewriting; a rewrite under someone else's feet loses their work.\n- If `reviewDecision` shows pending or approved reviews, surface that: review\n  comments anchor to commits and go stale after a rewrite. Ask before\n  continuing.\n\n### 2. Sync working tree\n\n```bash\ngit fetch origin --prune\ngit checkout \u003Chead-branch>\n```\n\nVerify clean working tree (`git status -s` returns empty). If dirty, stop and\nask the user. Never auto-stash without consent.\n\n### 3. Show the plan\n\nRun `git log --oneline origin\u002F\u003Cbase>..HEAD` and `git diff origin\u002F\u003Cbase> --stat`.\nState the intended action in plain words (e.g. \"I'll drop commit X by rebasing\n--onto origin\u002Fmain starting after it\"). **Wait for explicit user \"go\"** before\nrewriting.\n\n### 4. Rewrite\n\nUse the smallest-blast-radius command for the job:\n\n| Goal | Command |\n|---|---|\n| Resolve conflicts with new main | `git rebase origin\u002Fmain` |\n| Drop one commit in the middle | `git rebase --onto \u003Cbase> \u003Ccommit-to-drop> \u003Cbranch>` |\n| Reorder \u002F squash | non-interactive sequence edit, below: `git rebase -i` needs a terminal this environment does not have |\n| Reword last commit only | `git commit --amend` (verify HEAD is the right commit first) |\n| Split last commit | `git reset --soft HEAD~` then re-stage in parts |\n\nNon-interactive drop\u002Freorder: pipe the todo-list edit through the sequence\neditor rather than a terminal: `GIT_SEQUENCE_EDITOR=\u003Cscript> git rebase -i\n\u003Cbase>`, where the script edits `\"${1}\"` in place. Write the edit to a temporary\nfile and move it over the original rather than reaching for `sed -i`: the\nin-place flag takes a mandatory empty argument on BSD (`sed -i ''`) and refuses\none on GNU, so either spelling is broken on half the machines that install this\nskill.\n\nResolve the commit to a real object id first, and export it: git writes object\nids in the todo file, so a literal `\u003Csha>` matches nothing and the rebase\nreplays the branch unchanged, which looks like success.\n\n```bash\nexport DROP=$(git rev-parse --short=7 \u003Ccommit-to-drop>)\nGIT_SEQUENCE_EDITOR='f() { sed \"s\u002F^pick $DROP\u002Fdrop $DROP\u002F\" \"${1}\" > \"${1}.todo\" && mv \"${1}.todo\" \"${1}\"; }; f' \\\n  git rebase -i \u003Cbase>\n```\n\nSeven characters on purpose: git abbreviates the todo's ids to whatever the\nrepository needs, and a seven-character prefix still matches a longer one, while\na full forty-character id matches nothing at all.\n\n**If the rebase stops on a conflict**: resolve the conflicted files, `git add`\nthem, `git rebase --continue`; repeat per commit. If a resolution is not\nobviously right, `git rebase --abort` returns the branch to its pre-rebase\nstate and the question goes to the user: an aborted rebase loses nothing.\n\nRe-verify with `git log --oneline origin\u002F\u003Cbase>..HEAD` and `git diff\norigin\u002F\u003Cbase> --stat` after every step, and confirm `git diff HEAD` is empty: a\nnon-empty diff there means something outside the rebase (an editor with the\nfile open, a merge tool) rewrote the working tree, and committing would\nsilently fold that change in.\n\n### 5. Local checks before pushing\n\nRun the project's documented test command. Detect it, never assume a toolchain:\na `test` \u002F `check` \u002F `verify` recipe in `just --list`, else `scripts.test` in\n`package.json`, else a `test` target in the `Makefile`, else the language\ndefault (`bats tests\u002F`, `pytest`, `cargo test`, `go test .\u002F...`). Also run the\nlinter the repo's CI uses (read `.github\u002Fworkflows\u002F` for hints); if no lint\nstep is discoverable in the CI config or the task runner, skip linting and say\nso in the report. Never stall on the search. Don't push if checks fail: fix\nlocally first.\n\n### 6. Force-push with lease\n\n```bash\ngit push --force-with-lease origin \u003Cbranch>\n```\n\n**Never** plain `--force`. `--force-with-lease` refuses to clobber if the\nremote moved since the last fetch: if it rejects, stop and surface the diff\nbetween expected and actual remote state.\n\n### 7. Verify on the platform\n\n```bash\ngh pr view \u003CN> --json mergeable,mergeStateStatus,commits -q \\\n  '{state:.mergeStateStatus,mergeable:.mergeable,commits:[.commits[].messageHeadline]}'\n```\n\nConfirm `mergeable: MERGEABLE`, `mergeStateStatus: CLEAN` (or `UNSTABLE` while\nCI runs), and that the commit list matches the planned outcome. Report back.\n\n## When to STOP\n\n- **Branch is `main` or shared** → refuse. Suggest a revert PR or a forward-fix.\n- **`--force-with-lease` is rejected** by the remote → stop, surface the diff,\n  ask. Do not switch to plain `--force`.\n- **No explicit per-branch authorization for the force-push** → ask. Prior\n  authorization on one branch does not extend to another.\n- **PR has approved reviews or unresolved comments** → ask before rewriting;\n  reviewers may need to re-approve.\n- **CI was green and the rewrite is purely cosmetic** → ask whether it is worth\n  invalidating the run; sometimes a follow-up commit is better.\n- **Working tree is dirty** → ask the user. Never silently stash.\n",{"name":5,"description":7},"main","9435f9fa04b69d2217f8cab3c817dd5c3c1d1021","plugins\u002Fgit-workflow\u002Fskills\u002Frewrite-pr-history",0,"https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills","https:\u002F\u002Fgithub.com\u002Fdamson","http:\u002F\u002Fgoo.gl\u002F3UwFRt","2026-11-14 14:28:11",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add damson\u002Fhard-won-skills --skill rewrite-pr-history",{"tool":38,"command":39},"bunx","bunx skills add damson\u002Fhard-won-skills --skill rewrite-pr-history",{"tool":41,"command":42},"pnpm","pnpm dlx skills add damson\u002Fhard-won-skills --skill rewrite-pr-history","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fgit-workflow\u002Fskills\u002Frewrite-pr-history\u002FSKILL.md",true,[46],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"README.md","REFERENCE","参考文档",2369,"https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fgit-workflow\u002Fskills\u002Frewrite-pr-history\u002FREADME.md",[53,60,66,71,76,81],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7BRCESR9BRFAH87J2ZQY5T2","skill-two","Fixture skill","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fwrong_welcome_total\u002Fplugins\u002Falpha\u002Fskills\u002Fskill-two\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M7BRCDPHEPZES71BYBRTZ1G3","skill-one","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fwrong_welcome_total\u002Fplugins\u002Falpha\u002Fskills\u002Fskill-one\u002FSKILL.md",[],[],{"skillNo":67,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7BRCCHHB3Q07BR0QN339D3F","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fwrong_table_count\u002Fplugins\u002Falpha\u002Fskills\u002Fskill-two\u002FSKILL.md",[],[],{"skillNo":72,"name":62,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7BRC9J97QKZHGKVXMER5ZEE","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fwrong_table_count\u002Fplugins\u002Falpha\u002Fskills\u002Fskill-one\u002FSKILL.md",[],[],{"skillNo":77,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7BRC8C39NM8VVAQ3TKP0CRS","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fvalid_marketplace\u002Fplugins\u002Falpha\u002Fskills\u002Fskill-two\u002FSKILL.md",[],[],{"skillNo":82,"name":62,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M7BRC75THG394KDGYV35ET19","https:\u002F\u002Fgithub.com\u002Fdamson\u002Fhard-won-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fvalid_marketplace\u002Fplugins\u002Falpha\u002Fskills\u002Fskill-one\u002FSKILL.md",[],[]]