gitbutlerapp/gitbutler · error

Failed to create blank commit in leftmost stack

Error message

Failed to create blank commit in leftmost stack

What it means

Priority 3 fallback: the default (first) stack's first branch had no commits, a blank commit was inserted below it, and the re-fetched stack details still show no commits — so default-target absorption cannot proceed.

Source

Thrown at crates/but-api/src/legacy/absorb.rs:495

            .first()
            .ok_or_else(|| anyhow::anyhow!("Stack has no branches"))?;
        commit_insert_blank_only_impl(
            ctx,
            RelativeTo::Reference(branch.reference.clone()),
            InsertSide::Below,
            DryRun::No,
            perm,
        )?;

        // Now fetch the stack details again to get the newly created commit
        let stack_details = crate::legacy::workspace::stack_details(ctx, Some(stack_id))?;
        if let Some(branch) = stack_details.branch_details.first()
            && let Some(commit) = branch.commits.first()
        {
            return Ok((stack_id, commit.id, AbsorptionReason::DefaultStack));
        }

        anyhow::bail!("Failed to create blank commit in leftmost stack");
    }

    anyhow::bail!(
        "Unable to determine target commit for unassigned change: {}",
        candidate.hunk.path
    );
}

/// Prepare commit absorptions with commit summaries
///
/// This returns a vector of absorption information, sorted and ready for processing.
fn prepare_commit_absorptions(
    ctx: &Context,
    changes_by_commit: GroupedChanges,
) -> anyhow::Result<Vec<CommitAbsorption>> {
    let mut commit_absorptions = Vec::new();

    // Cache the stack details to determine the commit order

View on GitHub (pinned to 2497b8007a)

Solutions

  1. Reload the workspace and retry the absorb once
  2. Verify the first stack's branch shows the blank commit; if yes, the retry succeeds
  3. Eliminate concurrent writers (close other GitButler/git surfaces) and retry
  4. Report reproducible cases with tracing logs of the insert
Defensive patterns

Strategy: retry

Validate before calling

let stacks = workspace_stacks(ctx)?;
let first_ok = stacks.first()
    .and_then(|s| s.id)
    .map(|id| workspace_stack_details(ctx, id).map(|d| !d.branch_details.is_empty()).unwrap_or(false))
    .unwrap_or(false);
if !first_ok {
    // expect the blank-commit fallback; be ready to reload and retry once
}

Try / catch

match absorption_plan_with_perm(ctx, target.clone(), perm) {
    Err(e) if e.to_string().contains("Failed to create blank commit in leftmost stack") => {
        reload_workspace(ctx);
        absorption_plan_with_perm(ctx, target, perm) // one retry after cache drop
    }
    other => other,
}

Prevention

When it happens

Trigger: Same shape as the assigned-stack variant: the blank-commit insert succeeded but the refreshed workspace view still reports an empty first branch, due to stale cache or concurrent ref/workspace mutation.

Common situations: Racing pushes or branch updates; a second process writing the project; cache invalidation gap after the insert.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@2497b8007a (2026-08-17). Data as JSON: /api/errors/527d665a8ae396fe. Report an issue: GitHub.