{"record":{"id":"6f16c1d062cefdf6","repo":"GitoxideLabs/gitoxide","slug":"rewritten-commit-already-has-saved-worktree-sta","errorCode":null,"errorMessage":"rewritten commit {} already has saved worktree state","messagePattern":"rewritten commit (.+?) already has saved worktree state","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/stash.rs","lineNumber":96,"sourceCode":"            continue;\n        }\n        if let Some(other) = destinations.insert(new, old) {\n            anyhow::bail!(\n                \"stashes at {} and {} would converge on {}\",\n                other.to_hex_with_len(7),\n                old.to_hex_with_len(7),\n                new.to_hex_with_len(7)\n            );\n        }\n        moves.push((reference.name().to_owned(), reference.target().into_owned(), old, new));\n    }\n\n    let mut forward = Vec::with_capacity(moves.len() * 2);\n    let mut rollback = Vec::with_capacity(moves.len() * 2);\n    for (old_name, target, old, new) in moves {\n        let new_name = reference(new)?;\n        if repo.try_find_reference(new_name.as_ref())?.is_some() {\n            anyhow::bail!(\n                \"rewritten commit {} already has saved worktree state\",\n                new.to_hex_with_len(7)\n            );\n        }\n        forward.push(delete_edit(old_name.clone(), target.clone()));\n        forward.push(create_edit(new_name.clone(), target.clone()));\n        rollback.push(delete_edit(new_name, target.clone()));\n        rollback.push(create_edit(old_name, target));\n        tracing::debug!(old = %old, new = %new, \"prepared tix stash association rewrite\");\n    }\n    Ok(RewriteEdits { forward, rollback })\n}\n\nfn create_edit(name: gix::refs::FullName, target: Target) -> RefEdit {\n    RefEdit::update(name, target, PreviousValue::MustNotExist, \"tix commit stash rewrite\")\n}\n\nfn delete_edit(name: gix::refs::FullName, target: Target) -> RefEdit {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/stash.rs#L78-L114","documentation":"After a rewrite, tix stores saved worktree state under a reference named for the commit's NEW id. If a reference with that name already exists (from a previous stash or a collision), creating the new reference would overwrite unrelated saved state, so the operation aborts. The error names the short hash of the rewritten commit whose reference name collides.","triggerScenarios":"Calling `stash::rewrite_edits` when `repo.try_find_reference(reference(new))` returns `Some` — i.e. saved worktree state already exists under the rewritten commit's canonical stash name.","commonSituations":"Re-running a rewrite twice so the same rewritten ID is produced; reusing commit IDs after resets/amendments that kept old stash refs; hash collisions between separate stash sessions.","solutions":["Apply and then delete the pre-existing stash reference for that commit before re-running the rewrite","Rename or remove the stale reference if the old saved state is no longer needed","Choose a rewrite plan that produces a different destination commit ID for this stash"],"exampleFix":"// before re-running the rewrite\nrewrite_edits(&repo, plan)?;\n// after: clear the colliding ref first\nlet name = stash::reference(new_id)?;\nrepo.find_reference(name)?.delete()?;\nrewrite_edits(&repo, plan)?;","handlingStrategy":"validation","validationCode":"let name = stash::reference(new_id)?;\nif repo.try_find_reference(name.as_ref())?.is_some() {\n    anyhow::bail!(\"clear existing stash ref {} before rewriting\", name);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Before rewriting, list tix stash references and resolve ones whose names will collide with rewritten IDs","Avoid re-running identical rewrites without cleaning up stash refs from the first run","Use `try_find_reference(reference(new))` as a pre-flight check in automation"],"tags":["git","references","stash","collision"],"backgroundTag":"file-already-exists","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}