{"record":{"id":"4e839eec6edfe47b","repo":"gitbutlerapp/gitbutler","slug":"snapshot-checkout-and-workspace-commits-disagree","errorCode":null,"errorMessage":"snapshot checkout and workspace commits disagree","messagePattern":"snapshot checkout and workspace commits disagree","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":1143,"sourceCode":"            }\n\n            // TODO: in the next iteration, this of course can't be hardcoded.\n            if branch_name == \"workspace\" {\n                restored_workspace_commit = Some(commit_oid);\n            }\n        }\n    }\n    if let Some(checkout) = restored_checkout.as_ref() {\n        if !repo.has_object(checkout.commit_id) {\n            bail!(\n                \"snapshot checkout commit {} is unavailable\",\n                checkout.commit_id\n            );\n        }\n        if checkout.ref_name == workspace_ref\n            && restored_workspace_commit != Some(checkout.commit_id)\n        {\n            bail!(\"snapshot checkout and workspace commits disagree\");\n        }\n    }\n    // Managed snapshots already identify their checkout through the workspace commit entry.\n    let restored_checkout = restored_checkout.or_else(|| {\n        restored_workspace_commit.map(|commit_id| SnapshotCheckout {\n            ref_name: workspace_ref.to_owned(),\n            commit_id,\n        })\n    });\n\n    let head = repo.head()?;\n    let head_ref = head\n        .referent_name()\n        .context(\"We will not change a worktree in detached HEAD state\")?;\n    // Snapshots with neither checkout identity nor a workspace commit retain the old guard.\n    if restored_checkout.is_none() && head_ref != workspace_ref {\n        bail!(\"cannot restore a snapshot without checkout identity outside the workspace branch\");\n    }","sourceCodeStart":1125,"sourceCodeEnd":1161,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L1125-L1161","documentation":"Thrown by `restore_snapshot` when the snapshot's checkout entry points at the workspace ref but the commit recorded there disagrees with the workspace commit reconstructed from the snapshot's commit entries. The two redundant encodings of the workspace head must agree; disagreement means the snapshot data is internally inconsistent (corrupt or produced by incompatible code paths).","triggerScenarios":"`restore_snapshot` sees `checkout.ref_name == workspace_ref` while `restored_workspace_commit != Some(checkout.commit_id)` — e.g. the checkout blob was edited, or commit entries and the checkout blob were written by different snapshot versions.","commonSituations":"Manually editing snapshot blobs; mixing snapshot data across GitButler versions; partially copied/restored oplog trees where some blobs came from a different snapshot.","solutions":["Restore a different snapshot entry with consistent internal data","Inspect the snapshot tree (`git ls-tree`) and align the checkout-commit blob with the workspace commit entry if you know the intended head","Upgrade/downgrade GitButler so the snapshot format version matches the one that wrote the snapshot","Clear the oplog and re-snapshot current state if the snapshot set is inconsistent"],"exampleFix":"// checkout blob says abc123, workspace commit entry says def456\n// before: bail 'snapshot checkout and workspace commits disagree'\n// after:  fix checkout blob to def456 (or restore consistent snapshot)","handlingStrategy":"validation","validationCode":"// assert the two encodings agree before calling restore\nif checkout.ref_name == workspace_ref\n    && restored_workspace_commit != Some(checkout.commit_id) {\n    return Err(\"snapshot data inconsistent; pick another snapshot entry\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mix snapshot blobs from different oplog entries or versions","Restore whole snapshot entries, not hand-assembled subsets","Keep GitButler updated so snapshot write paths stay consistent","Compare the checkout blob and workspace commit entry with `git ls-tree` when in doubt"],"tags":["git","snapshot","consistency","internal-state"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}