gitbutlerapp/gitbutler · error

Failed to create blank commit in stack

Error message

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

What it means

`ensure_target_commit` throws this when, to absorb changes for an assigned stack, it creates a blank commit in the stack and then re-projects the workspace — but the freshly created commit cannot be found via `target_segment`, meaning the blank commit did not materialize as the stack's tip commit. This is an internal consistency failure of the stack-projection step, so the operation bails.

Solutions

  1. Retry the absorb operation — a transient concurrent mutation may have caused the failed projection.
  2. Refresh the workspace state (`but pull`, re-open the project) and verify the stack is intact, then retry.
  3. If reproducible, inspect for concurrent GitButler clients or ref-mutating automation and report a bug — this is an internal invariant violation.

Example fix

// before
absorb(hunks)  // Err: Failed to create blank commit in stack: StackId(..)
// after
but pull; // refresh workspace
assert_stack_intact(stack_id);
absorb(hunks)
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

try {
  await api.absorb(hunks);
} catch (e) {
  if (String(e).includes('Failed to create blank commit in stack')) {
    await api.refreshWorkspace(); // re-project stacks, ensure single client
    await api.absorb(hunks);      // retry once; persisting failures are a bug
  } else throw e;
}

Prevention

When it happens

Trigger: Calling hunk/change absorption where the stack-assignment path (Priority 2) creates a blank commit in `stack_id`, re-reads `head_info`, but `target_segment(workspace, stack_id, branch_ref)` returns `(_, None)` — the projected tip commit is missing.

Common situations: Concurrent workspace mutations (another client/process rebasing the stack between commit creation and re-projection); stack state that cannot be projected consistently (e.g. conflicting ref updates); bugs in the workspace projection after automation touched refs.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/4dd5397e0b11368b. Report an issue: GitHub.

Appendix: source

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

            return Ok((stack_id, commit_id, AbsorptionReason::StackAssignment));
        }

        // If there are no commits in the target branch, create a blank commit first
        commit_insert_blank_only_impl(
            ctx,
            RelativeTo::Reference(reference),
            InsertSide::Below,
            DryRun::No,
            perm,
        )?;

        // Project the workspace again to see the newly created commit
        *workspace = crate::legacy::workspace::head_info(ctx)?;
        if let (_, Some(commit_id)) = target_segment(workspace, stack_id, branch_ref)? {
            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
    if let Some(stack_id) = workspace.stacks.first().and_then(|stack| stack.id) {
        let (reference, commit_id) = target_segment(workspace, stack_id, None)?;
        if let Some(commit_id) = commit_id {
            return Ok((stack_id, commit_id, AbsorptionReason::DefaultStack));
        }

        // If the first stack has no commits, create a blank commit first
        commit_insert_blank_only_impl(
            ctx,
            RelativeTo::Reference(reference),
            InsertSide::Below,
            DryRun::No,
            perm,
        )?;

View on GitHub (pinned to 58e5313667)