gitbutlerapp/gitbutler · error
Could not find associated reference name
Error message
Could not find associated reference name
What it means
handle_changes buckets hunk assignments by stack ID (stack_assignments.entry(stack_id).or_default()), then resolves each bucket back to a stack to get its branch name for refs/heads/<name>. This error fires when a bucket's stack_id has no entry in the stacks list collected at the start — a hunk assignment in the database references a stack that no longer exists in the workspace.
Source
Thrown at crates/but-action/src/simple.rs:113
} else {
change_summary.to_string()
};
for (stack_id, diff_specs) in stack_assignments {
if diff_specs.is_empty() {
continue;
}
if let Some(exclusive_stack) = exclusive_stack
&& exclusive_stack != stack_id
{
continue; // Skip stacks that are not the exclusive stack.
}
let stack_branch_name = stacks
.iter()
.find(|s| s.id == stack_id)
.map(|s| s.branch_name.clone())
.ok_or(anyhow!("Could not find associated reference name"))?;
let full_ref_name: gix::refs::FullName =
format!("refs/heads/{stack_branch_name}").try_into()?;
let editor = Editor::create(ws, meta, repo, db)?;
let outcome = but_workspace::commit::commit_create(
editor,
diff_specs,
RelativeToRef::Reference(full_ref_name.as_ref()),
InsertSide::Below,
&commit_message,
context_lines,
but_workspace::commit::ChangeSource::Head,
)?;
if !outcome.rejected_specs.is_empty() {
tracing::warn!(
?outcome.rejected_specs,
"Failed to commit at least one hunk"View on GitHub (pinned to 2497b8007a)
Solutions
- Reassign the pending changes to an existing stack in the GitButler UI, then retry.
- Clear the stale hunk assignments for the missing stack in the assignment store, or discard the affected hunks.
- If it recurs right after deleting a stack, report it — deletion should have cleaned up those assignment rows.
Defensive patterns
Strategy: validation
Validate before calling
use std::collections::HashSet;
let live_ids: HashSet<StackId> = stacks.iter().map(|s| s.id).collect();
for a in &assignments {
if let Some(id) = a.stack_id {
anyhow::ensure!(live_ids.contains(&id), "assignment targets missing stack {id}");
}
} Prevention
- After deleting a stack, always unassign or reassign its hunks.
- Prune assignment rows whose stack IDs no longer resolve.
- Surface assignment-to-stack mismatches before running commit-creating actions.
When it happens
Trigger: handle_changes with stale hunk_assignment rows whose stack_id points at a deleted or unapplied stack: stacks come only from stacks_creating_if_none (current applied stacks), while assignments come from the DB, so any drift between them trips the lookup.
Common situations: Deleting a stack while hunks were still assigned to it; crashes between stack deletion and assignment cleanup; restored or migrated assignment data referencing old stack IDs.
Related errors
- No stacks found in the workspace
- Cannot handle changes while in edit mode. Please exit edit m
- Branch not found: {branch_name}
- Stack has no ID
- No uncommitted changes assigned to branch: {branch_name}
AI-assisted analysis of gitbutlerapp/gitbutler@2497b8007a (2026-08-17).
Data as JSON: /api/errors/03304469b0212602.
Report an issue: GitHub.