zed-industries/zed · error

Failed to apply stash: {}

Error message

Failed to apply stash:
{}

What it means

ensure! guard failing when `git stash apply [stash@{N}]` exits non-zero. Applying the stashed changes failed — usually due to conflicts with current worktree contents or a stale stash index reference.

Source

Thrown at crates/git/src/repository.rs:2651

                    .args(paths.iter().map(|p| p.as_unix_str()))
                    .output()
                    .await?;

                anyhow::ensure!(
                    output.status.success(),
                    "Failed to stash:\n{}",
                    String::from_utf8_lossy(&output.stderr)
                );
                Ok(())
            })
            .boxed()
    }

    fn stash_staged(
        &self,
        message: Option<String>,
        env: Arc<HashMap<String, String>>,
    ) -> BoxFuture<'_, Result<()>> {
        let git = self.git_binary_in_worktree();
        self.executor
            .spawn(async move {
                let git = git?;
                // `--staged` cannot be expressed as a pathspec: a partially staged
                // file would otherwise have its unstaged hunks stashed too.
                let mut args = vec!["stash", "push", "--quiet", "--staged"];
                if let Some(message) = message.as_deref() {
                    args.extend_from_slice(&["--message", message]);
                }
                let output = git.build_command(&args).envs(env.iter()).output().await?;

                anyhow::ensure!(
                    output.status.success(),
                    "Failed to stash staged changes (requires git 2.35 or newer):\n{}",
                    String::from_utf8_lossy(&output.stderr)
                );
                Ok(())

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Inspect stderr for conflict messages and surface them to the user; apply keeps the stash entry so nothing is lost
  2. Re-check the stash list before applying; stash@{N} may point elsewhere after changes
  3. Commit or stash current changes before applying to reduce conflict likelihood
  4. Retry apply after the user resolves conflicts
Defensive patterns

Strategy: try-catch

When it happens

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

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20). Data as JSON: /api/errors/83e9b2af07965b6c. Report an issue: GitHub.