Pull request analysis diffing

How DeepSource filters issues on pull requests, including behavior on stacked PRs and PRs targeting non-default branches.

When DeepSource analyzes a pull request, it compares the code changes against a baseline to determine which issues are new (introduced by the PR) and which are pre-existing (already present in the codebase). This process is called issue diffing and it controls what gets reported on the PR.

You can configure the diffing mode in Settings > General > Analysis result diffing. See Analysis result diffing for details on each mode.

How baseline diffing works

In Baseline mode (the default and recommended setting), DeepSource reports only the issues found on lines modified in the pull request, compared against the configured default branch. This keeps PR feedback focused on what the author actually changed.

For each PR analysis run, DeepSource:

  1. Analyzes the full set of files changed in the PR.
  2. Compares the results against the issues existing on the default branch (the baseline) of the repository.
  3. Reports only the issues that are new, i.e., present in the PR but not in the baseline.

Stacked PRs and PRs targeting non-default branches

A stacked PR is a pull request whose base branch is not the default branch. For example, a feature branch based on another feature branch, or a PR targeting a release or QA branch.

DeepSource supports issue diffing on stacked PRs. To build an accurate baseline, DeepSource walks the chain of open pull requests from the PR's base branch up to the default branch, collecting issues from each intermediate branch along the way. The combined set of issues from the default branch and all parent branches in the stack forms the baseline for diffing.

For example, if your stack looks like feature-cfeature-bfeature-amain, and each link has an open PR, DeepSource will combine issues from feature-b, feature-a, and main to determine which issues in feature-c are actually new.

Why inaccuracies can occur

Incomplete PR chain

DeepSource resolves parent branches by following open pull requests. If any PR in the chain is missing or closed, the resolution stops and the baseline becomes incomplete — issues introduced in a parent branch may then be incorrectly reported as new in your PR. When this happens, DeepSource shows a warning:

Since the parent branch of this pull request doesn't have its own pull request, the baseline analysis may not be accurate. Some of the issues raised might belong to one of the parent branches.

To fix this, ensure every branch in the stack has an open PR targeting the next branch in the chain, all the way to the default branch.

Branch divergence

Even when the PR chain is complete, inaccuracies can occur if the base branch has diverged from the default branch:

  • Pre-existing issues may reappear as new: If the base branch contains issues that don't exist on the default branch (e.g., because of independent changes), those issues can be incorrectly flagged as newly introduced by the PR.
  • Issues may simultaneously show as resolved and re-raised: When the branches are out of sync, DeepSource may not be able to reliably match pre-existing issues to their counterparts on the default branch. This can cause the same issues to appear as resolved and then re-raised in the same PR run. This typically happens when:
    • Line ranges have shifted: Code changes on the base branch cause existing issues to move to different line numbers, making them look like new issues. Rebasing the PR's base branch onto the default branch fixes this in most cases.
    • Key issue details have changed: If a property of an existing issue changes (e.g., cyclomatic complexity of a function increased or decreased), DeepSource intentionally treats it as a new issue since the underlying code characteristic has changed.

The further the base branch has drifted from the default branch, the more likely these discrepancies are.

Keeping PR analysis accurate

To ensure issue diffing remains reliable on stacked PRs:

Rebase the base branch

If you notice issues being raised on untouched lines of a PR opened against a non-default branch, rebase the PR's base branch onto the default branch. This re-aligns the code state so that the diff comparison is accurate.

For example, if your PR targets qa-backup and the default branch is main:

git checkout qa-backup
git rebase main

Then update or re-open the PR to trigger a fresh analysis.

Keep the default branch in sync

Ensure the default branch configured on DeepSource matches the default branch of your repository on your version control provider (e.g., GitHub, GitLab, Bitbucket). You can verify this in Settings > General > Default branch. See Default branch for more.

When these are aligned, the baseline analysis stays current with the latest merged code, and feature branches rebased onto the default branch produce accurate diffs.

If the default branch on DeepSource and the VCS default branch are different, the baseline analysis may be stale or based on a different code state. This is the most common cause of unexpected issue diffing behavior on stacked PRs.

Summary

ScenarioExpected behavior
PR against the default branchIssues are accurately diffed against the latest default branch analysis.
Stacked PR, full PR chain exists, base branch rebased with defaultIssues are accurately diffed. Pre-existing issues on all parent branches are filtered out.
Stacked PR, a PR is missing in the chainIncomplete baseline: issues from parent branches may appear as new. A warning is shown on the analysis run.
Stacked PR, base branch out of sync with defaultInaccurate results: pre-existing issues may appear as new, and unrelated issues may show as resolved.

On this page