zed-industries/zed · error

diff has no unstaged secondary

Error message

diff has no unstaged secondary

What it means

During stage/unstage of git hunks, a hunk's diff was read but its secondary_diff (the baseline diff against the other side, e.g. HEAD vs index) was None. The stage operation needs the secondary diff to apply the inverse/base representation, so this sentinel guard reports that the unstaged baseline is missing and the hunk cannot be staged through the normal path.

Source

Thrown at crates/editor/src/git.rs:134

        for hunks in hunks {
            let Some(buffer) = hunks.buffer else {
                continue;
            };

            let ranges = hunks
                .hunks
                .into_iter()
                .map(|hunk| hunk.buffer_range)
                .collect::<Vec<_>>();
            if ranges.is_empty() {
                continue;
            }
            let secondary_diff = hunks.diff.read(cx).secondary_diff();
            project
                .update(cx, |project, cx| {
                    if stage {
                        let Some(secondary_diff) = secondary_diff else {
                            return Err(anyhow::anyhow!("diff has no unstaged secondary"));
                        };
                        project.stage_hunks(buffer, secondary_diff, ranges, cx)
                    } else {
                        project.unstage_uncommitted_hunks(buffer, hunks.diff, ranges, cx)
                    }
                })
                .log_err();
        }
    }

    fn render_hunk_controls(
        &self,
        row: u32,
        status: &DiffHunkStatus,
        hunk_range: Range<Anchor>,
        is_created_file: bool,
        line_height: Pixels,
        editor: &Entity<Editor>,

View on GitHub (pinned to f4178619ac)

Solutions

  1. Skip the affected hunk and continue staging the remaining hunks, reporting which ones were skipped
  2. Refresh the buffer diff (git status/index may have changed underneath) and retry before giving up
  3. Fall back to invoking git apply/git add directly for the hunk's range
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/editor/src/git.rs:134 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/81d91f44d626202e. Report an issue: GitHub.