gitbutlerapp/gitbutler · error

Failed to create blank commit in stack: {stack_id:?}

Error message

Failed to create blank commit in stack: {stack_id:?}

What it means

Priority 2 fallback: the assigned stack's target branch has no commits, so a blank commit is inserted below the branch reference via commit_insert_blank_only_impl() and stack details are re-fetched. If the re-fetch still shows no commits on that branch, the insert did not materialize in the workspace view and absorption bails.

Source

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

        let branch = find_target_branch(&stack_details, branch_ref)
            .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,
        )?;

        // Fetch again to get the newly created commit
        let stack_details = crate::legacy::workspace::stack_details(ctx, Some(stack_id))?;
        if let Some(branch) = find_target_branch(&stack_details, branch_ref)
            && let Some(commit) = branch.commits.first()
        {
            return Ok((stack_id, commit.id, AbsorptionReason::StackAssignment));
        }

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

    // Priority 3: If no assignment, find the topmost commit of the leftmost lane
    let stacks = crate::legacy::workspace::stacks(ctx, None)?;
    if let Some(stack) = stacks.first()
        && let Some(stack_id) = stack.id
    {
        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));
        }

        // If the first stack has no commits, create a blank commit first
        let branch = stack_details
            .branch_details
            .first()

View on GitHub (pinned to 2497b8007a)

Solutions

  1. Retry the absorb once after reloading the workspace view
  2. Verify in the stacks UI that the blank commit actually appeared; if it did, a plain retry succeeds
  3. Close competing GitButler/git processes for the same project and retry
  4. If reproducible, capture logs — insert Ok but empty refetch indicates a cache/invalidation bug worth reporting
Defensive patterns

Strategy: retry

Validate before calling

let details = workspace_stack_details(ctx, stack_id)?;
let branch_has_commits = details.branch_details.iter()
    .find(|b| Some(&b.reference) == branch_ref.as_ref())
    .or_else(|| details.branch_details.first())
    .is_some_and(|b| !b.commits.is_empty());
if !branch_has_commits {
    // blank-commit path will run; be ready to reload and retry once
}

Try / catch

let mut last_err = None;
for attempt in 0..2 {
    match absorption_plan_with_perm(ctx, target.clone(), perm) {
        Ok(plan) => return Ok(plan),
        Err(e) if attempt == 0 && e.to_string().contains("Failed to create blank commit") => {
            reload_workspace(ctx); // drop caches, then retry once
            last_err = Some(e);
        }
        Err(e) => return Err(e),
    }
}
return Err(last_err.unwrap());

Prevention

When it happens

Trigger: The blank-commit insert returned Ok but the refetched stack details still report an empty branch: stale metadata cache, the branch reference moved concurrently, or another writer updated the workspace between insert and re-fetch.

Common situations: Concurrent GitButler operations (push, branch update) racing absorb; a second process (CLI while the GUI is open) mutating the same project; metadata cache invalidation gaps after insert.

Related errors


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