gitbutlerapp/gitbutler · error

Failed to create blank commit in leftmost stack

Error message

Failed to create blank commit in leftmost stack

What it means

During absorb, when an unassigned change is grouped, ensure_target_commit tries to find (or create) a blank commit at the top of the leftmost stack to absorb the change into. If after re-projecting the workspace the target segment still cannot be resolved, this error is thrown. It indicates the workspace could not provide a valid target commit for the change.

Solutions

  1. Re-run project/workspace refresh and retry the absorb operation
  2. Inspect the leftmost stack state (gitbutler workspace refs) and repair or recreate the stack
  3. Check for concurrent processes modifying the repo during absorb
  4. Reproduce with but workspace status and report if projection consistently fails
Defensive patterns

Strategy: try-catch

Validate before calling

const ws = await getWorkspaceStatus(projectId);
if (!ws.stacks?.length) { await createInitialStack(projectId); }

Try / catch

try {
  await absorbChanges(projectId, changes);
} catch (e) {
  if (String(e).includes('Failed to create blank commit')) {
    await refreshWorkspace(projectId);
    await absorbChanges(projectId, changes);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling absorb (via group_changes_by_target_commit) on a workspace whose leftmost stack has no resolvable target segment even after creating a blank commit; workspace re-projection returns no commit for the stack.

Common situations: Absorbing unassigned hunks in a workspace with an empty or corrupted leftmost stack; repository state changed mid-operation (e.g. concurrent git operations or external tooling rewrote refs); workspace projection returning stale/empty data.

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/527d665a8ae396fe. Report an issue: GitHub.

Appendix: source

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

            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,
        )?;

        // Now 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, None)? {
            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();

    // The workspace projection carries every stack's segments and commits in order

View on GitHub (pinned to 58e5313667)