gitbutlerapp/gitbutler · error
Commit is not in the applied workspace
Error message
Commit {} is not in the applied workspace What it means
create_comment anchors a diff comment to a file within the applied workspace. It builds ScopeDiffs for the workspace and looks up a file anchor by commit-change-id and path; if no anchor is found, the target commit/file is not part of the currently applied workspace and the function bails with this message.
Solutions
- Verify the commit is currently applied in the workspace (list workspace commits before commenting)
- Re-resolve the commit_change_id against the current workspace state instead of using a cached value
- Confirm the file path exists in that commit's changes
- Refresh the workspace/reload state and retry if the workspace changed concurrently
Example fix
// before
create_comment(repo, workspace, comment, context_lines, now_ms).await?;
// after
anyhow::ensure!(
workspace.applied().iter().any(|c| c.id == comment.commit_change_id),
"commit {} not applied; refresh workspace first",
comment.commit_change_id
);
create_comment(repo, workspace, comment, context_lines, now_ms).await?; Defensive patterns
Strategy: validation
Validate before calling
let applied: Vec<_> = workspace.applied().iter().map(|c| c.id.clone()).collect();
anyhow::ensure!(applied.contains(&comment.commit_change_id), "commit {} not applied", comment.commit_change_id); Type guard
fn is_applied(workspace: &Workspace, commit_change_id: &Option<String>) -> bool {
commit_change_id.as_deref()
.map(|id| workspace.applied().iter().any(|c| c.id == id))
.unwrap_or(false)
} Try / catch
match create_comment(repo, workspace, comment, ctx, now).await {
Err(e) if e.to_string().contains("not in the applied workspace") => refresh_workspace_and_retry()?,
other => other?,
} Prevention
- Re-resolve commit_change_id against current workspace state before commenting
- Re-check that the commit is applied after any workspace rebase/apply
- Validate the file path exists in the commit's changes
- Never cache commit-change-ids across workspace mutations
When it happens
Trigger: Calling create_comment with a comment whose commit_change_id (or its path) does not resolve to a file in the applied workspace — e.g. the commit was unapplied, the workspace changed, or the id/path is wrong.
Common situations: Commenting on a commit that was later unapplied or squashed; stale commit-change-id captured before a workspace rebase; referencing a file path that no longer exists in the commit; passing the wrong workspace.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- a committed transaction always materializes a workspace
- AtSegment anchor always has oldest commit resolved
- Branch ` ` is not part of the current workspace
- Cannot unapply anonymous segments yet even if they have a…
- Cannot
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e494790f9c068288.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-comments/src/lib.rs:131
/// Create a new comment anchored to a line in a diff.
///
/// The anchor must point at a line that exists in the current diff — the uncommitted worktree
/// diff of `path`, or the first-parent diff of the workspace commit with `commit_change_id` —
/// otherwise an error is returned. The anchored line's content (and its neighbours) is
/// snapshotted so the comment can be re-located when the diff drifts.
pub fn create_comment(
repo: &gix::Repository,
workspace: &but_graph::Workspace,
store: &CommentStore,
comment: NewComment,
context_lines: u32,
now_ms: i64,
) -> anyhow::Result<DiffComment> {
let scope = anchor_scope_display(&comment.commit_change_id, &comment.path);
let mut diffs = ScopeDiffs::new(repo, workspace, context_lines);
let Some(anchor) = diffs.file(comment.commit_change_id.as_deref(), &comment.path)? else {
bail!(
"Commit {} is not in the applied workspace",
comment.commit_change_id.as_deref().unwrap_or_default()
);
};
let file = match anchor {
FileAnchor::Lines(lines) => lines,
FileAnchor::Gone => bail!("Nothing to anchor a comment to in {scope}"),
FileAnchor::Unanchorable => {
bail!("Cannot comment on {scope}: the diff is binary or too large")
}
};
let line = file
.line_at(comment.side, comment.line_number)
.with_context(|| {
format!(
"No line {} on the {} side in {scope}",
comment.line_number,
comment.side.as_str(),View on GitHub (pinned to 58e5313667)