diff --git a/CLAUDE.md b/CLAUDE.md index 17dd456..f59d659 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -66,11 +66,16 @@ Stacked branches share commits (each child contains its ancestors). Prefer expli ### Recovery if a child PR gets closed by base-branch deletion -1. Restore the deleted base branch ref at the merge commit's second parent: - `gh api --method POST repos///git/refs -f ref=refs/heads/ -f sha=$(git rev-parse origin/main^2)` +This happens when the **parent** PR is merged with `--delete-branch`: deleting the parent's head branch (which is the child's base) closes the **child** PR. Two PRs are involved — the merged parent (``) and the closed child (``); `` is the deleted base, i.e. the parent's head branch. + +1. Restore the deleted base branch ref at the **parent** merge commit's second parent (the deleted branch's pre-merge tip). Resolve the merge commit from `` — the PR that actually merged — **not** the closed child (it's unmerged, so its `mergeCommit` is `null` and `git rev-parse` would fail), and **not** `origin/main^2` (only that second parent while the parent merge is still `main`'s tip; any later merge, or a squash/rebase tip, makes it the wrong SHA): + ```bash + MERGE_SHA=$(gh pr view --repo / --json mergeCommit --jq .mergeCommit.oid) + gh api --method POST repos///git/refs -f ref=refs/heads/ -f sha=$(git rev-parse "$MERGE_SHA^2") + ``` 2. Reopen the child via **REST** (GraphQL `gh pr reopen` fails on the Projects-classic deprecation): - `gh api --method PATCH repos///pulls/ -f state=open` -3. Retarget it: `gh pr edit --base main` (only works once it's open). + `gh api --method PATCH repos///pulls/ -f state=open` +3. Retarget it: `gh pr edit --base main` (only works once it's open). ### Other gotchas