Skip to content

fix: filter already-merged commits from PR range context#1521

Closed
zerone0x wants to merge 1 commit intopingdotgg:mainfrom
zerone0x:fix/cherry-pick-pr-commit-log
Closed

fix: filter already-merged commits from PR range context#1521
zerone0x wants to merge 1 commit intopingdotgg:mainfrom
zerone0x:fix/cherry-pick-pr-commit-log

Conversation

@zerone0x
Copy link
Copy Markdown

@zerone0x zerone0x commented Mar 29, 2026

Summary

Fixes #1487

When generating PR title and body, readRangeContext uses git log --oneline baseBranch..HEAD to collect the commit summary that feeds into the LLM prompt. On long-lived branches where previous PRs were squash-merged (or merge-committed) into the base branch, this range includes all old commits whose SHAs differ from what landed on the base — even though their patch content is already upstream. The LLM then generates a title dominated by stale commit messages from previously merged PRs.

Root cause: git log main..HEAD lists commits reachable from HEAD but not from main by commit identity (SHA). After a squash-merge, the original commits on the feature branch have different SHAs than the squash commit on main, so they all appear in the log — even though the actual code changes are already in main.

Fix: Add --cherry-pick --right-only flags to the git log command in readRangeContext. These flags tell git to compare patch-ids (content hashes of each commit's diff) and skip any commit on the right side (HEAD) whose patch already exists on the left side (base branch). This filters out commits from previously merged PRs, ensuring only genuinely new commits feed into PR content generation.

This is a single-line change with no network overhead (unlike fetching the base branch), works entirely locally, and gracefully handles all merge strategies (squash, merge commit, rebase).

Changed file: apps/server/src/git/Layers/GitCore.tsreadRangeContext method

Test plan

  • On a long-lived branch with previously squash-merged PRs, run commit+push+PR — verify the generated PR title only reflects new changes
  • On a fresh feature branch with no prior PRs, verify PR generation works normally
  • Verify the existing readRangeContext test still passes (it creates fresh commits not present on the base, so --cherry-pick won't filter them)

🤖 Generated with Claude Code


Note

Low Risk
Low risk: a small change to the git log invocation used for PR context generation; it only affects which commits appear in the summary, not repository state or data writes.

Overview
Updates GitCore.readRangeContext to call git log with --cherry-pick --right-only for the base..HEAD range, filtering out commits whose patch content already exists on the base branch.

This reduces stale/previously-merged commit messages from being included in the commit summary used to generate PR titles/bodies, while leaving diff stat/patch collection unchanged.

Written by Cursor Bugbot for commit 5f2aaf0. This will update automatically on new commits. Configure here.

Note

Filter already-merged commits from readRangeContext PR range summary

Adds --cherry-pick and --right-only flags to the git log call in readRangeContext (GitCore.ts). This limits the commit summary to the right side of the range and excludes commits whose patches already exist on the other side (e.g. cherry-picks). Behavioral Change: the set of commits appearing in the PR range summary may change for branches that share cherry-picked commits with their base.

Macroscope summarized 5f2aaf0.

When generating PR title and body, `readRangeContext` uses
`git log --oneline baseBranch..HEAD` to collect commit summaries.
On long-lived branches where previous PRs were squash-merged into
the base branch, this range includes old commits whose patch
content already exists upstream. The LLM then generates titles
reflecting stale work.

Adding `--cherry-pick --right-only` to the git log command tells
git to skip commits whose patch-id matches a commit already
reachable from the base branch. This ensures only genuinely new
commits feed into PR content generation, so each PR gets a fresh
title based on its own changes.

Fixes pingdotgg#1487

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 74649005-4865-4dfc-873c-293edb93a8ac

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 29, 2026
@zerone0x
Copy link
Copy Markdown
Author

Closing duplicate — #1519 is the primary fix for this issue.

@zerone0x zerone0x closed this Mar 29, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

"GitCore.readRangeContext.log",
cwd,
["log", "--oneline", range],
["log", "--oneline", "--cherry-pick", "--right-only", range],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--cherry-pick --right-only requires triple-dot range notation

High Severity

The --cherry-pick and --right-only flags are silently ignored because the range variable uses double-dot notation (baseBranch..HEAD). These flags require triple-dot symmetric difference notation (baseBranch...HEAD) to work — Git needs to see commits from both sides simultaneously to identify patch-id equivalents. With double-dot, the intended filtering of already-merged commits simply doesn't happen. The git log command needs its own triple-dot range, separate from the git diff commands which correctly use double-dot.

Additional Locations (1)
Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Generated PR title keeps being reused on new PRs

1 participant