Skip to content

Commit bc4dba7

Browse files
committed
squash merge clarification
1 parent f7bc73f commit bc4dba7

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

docs/src/content/docs/faq.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,41 @@ You cannot merge a PR in the middle of the stack before the PRs below it are mer
100100

101101
### How does squash merge work?
102102

103-
Squash merges are fully supported. Each PR in the stack produces one clean, squashed commit when merged. The rebase engine automatically detects squash-merged PRs and replays commits from the remaining branches onto the squashed result.
103+
Squash merges are fully supported. Each PR in the stack produces one clean, squashed commit when merged. Merging `n` PRs will create `n` squashed commits on the base.
104+
105+
When a PR is squash-merged, the original commits disappear from the history, which can cause artificial merge conflicts during rebasing. Both the CLI and the server handle this using `git rebase --onto`:
106+
107+
```
108+
git rebase --onto <new_commit_sha_generated_by_squash> <original_commit_sha_from_tip_of_merged_branch> <branch_name>
109+
```
110+
111+
**Example:** Consider a stack with three PRs:
112+
113+
```
114+
PR1: main ← A, B (branch1)
115+
PR2: main ← A, B, C, D (branch2)
116+
PR3: main ← A, B, C, D, E, F (branch3)
117+
```
118+
119+
When PR1 and PR2 are squash-merged, `main` now looks like:
120+
121+
```
122+
S1 (squash of A+B), S2 (squash of C+D)
123+
```
124+
125+
Then the following rebase is run:
126+
127+
```
128+
git rebase --onto S2 D branch3
129+
```
130+
131+
Which rewrites `branch3` to:
132+
133+
```
134+
S1, S2, E, F
135+
```
136+
137+
This moves the unique commits from the unmerged branch and replays them on top of the newly squashed commits on the base branch, avoiding any merge conflicts.
104138

105139
### How does merge commit work?
106140

docs/src/content/docs/introduction/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Rebasing is the trickiest part of working with Stacked PRs, and GitHub handles i
7777
- **In the PR UI** — A rebase button lets you trigger a cascading rebase across all branches in the stack.
7878
- **From the CLI**`gh stack rebase` performs the same cascading rebase locally.
7979
- **After partial merges** — When you merge a PR at the bottom of the stack, the remaining branches are automatically rebased so the next PR targets `main` and is ready for review and merge.
80+
- **Safe squash-merge handling** — Squash merges are fully supported. The rebase engine safely replays your unique commits on top of the squashed base, avoiding artificial merge conflicts. See the [FAQ](/gh-stack/faq/#how-does-squash-merge-work) for a detailed description of how this works.
8081

8182
## The CLI: `gh stack`
8283

0 commit comments

Comments
 (0)