Prefer complete merged changes when backporting squash-merged PRs - #17218
Merged
Conversation
Prefer verified complete one-parent merge changes and fetch pull request refs before falling back to git am. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the reusable backport workflow to avoid replaying intermediate PR commits (via git am) when the final merged PR change can be safely applied as a single commit, reducing unnecessary conflicts—especially for squash-merged PRs and PRs from forks.
Changes:
- Downloads both the full mailbox patch series and the complete PR diff, then compares patch-ids to verify whether the merged commit represents the full PR change.
- Preferentially cherry-picks the merged commit when verification succeeds, otherwise falls back to
git am. - Fetches
refs/pull/<number>/headbeforegit amto improve three-way patch application when PR objects aren’t present locally.
Comments suppressed due to low confidence (1)
.github/workflows/backport-base.yml:304
merged_diff_fileis not guaranteed to exist (e.g., no merge_commit_sha, or merge commit with >2 parents, or verification skipped).git reset HEAD -- ... ${merged_diff_file}will fail if the file is missing, which can break the conflict-resolution flow after a failedgit am. Make the reset conditional on the file existing.
await exec.exec(`git reset HEAD -- ${patch_file} ${diff_file} ${merged_diff_file}`);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
akoeplinger
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17205.
The backport workflow currently replays every original PR commit using
git am. Intermediate commits can conflict with the target branch even when the final merged change applies cleanly.This change:
git patch-id --verbatim.git amfor multi-commit rebases, two-parent merge commits, unverifiable cases, and workflows specifying additionalgit amswitches.refs/pull/<number>/headbeforegit am, providing objects required for three-way application of patches from forks.The production workflow script was exercised in dry mode against squash, merge-commit, rebase, missing-object, custom-switch, and conflict scenarios. Here, "dry mode" means the actual inline script ran against temporary local Git repositories with mocked GitHub APIs and intercepted pushes.
Note
This pull request was created with GitHub Copilot.