{"record":{"id":"4e0bd2405b0e1c00","repo":"gitbutlerapp/gitbutler","slug":"could-not-discard-all-selected-changes-refused-p","errorCode":null,"errorMessage":"Could not discard all selected changes: {refused_paths}","messagePattern":"Could not discard all selected changes: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/discard.rs","lineNumber":579,"sourceCode":"                    let new_commit = tx.discard_changes_from_commit(source.commit_id, changes)?;\n                    DiscardOutcome::CommittedChanges {\n                        source,\n                        paths,\n                        new_commit: new_commit.into(),\n                    }\n                }\n                ExecutableDiscardOperation::Uncommitted { paths, changes } => {\n                    let refused = but_workspace::discard_workspace_changes(\n                        tx.repo(),\n                        changes,\n                        tx.context_lines(),\n                    )?;\n                    if !refused.is_empty() {\n                        let refused_paths = refused\n                            .iter()\n                            .map(|change| change.path.as_bstr())\n                            .join(\", \");\n                        bail!(\"Could not discard all selected changes: {refused_paths}\");\n                    }\n                    DiscardOutcome::Uncommitted { paths }\n                }\n            };\n\n            Ok(Commit(outcome))\n        },\n    )?;\n\n    if let DiscardOutcome::Commits {\n        replaced_commits, ..\n    } = &mut outcome\n    {\n        *replaced_commits = std::mem::take(&mut ws.replaced_commits);\n    }\n\n    Ok((outcome, ws))\n}","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/discard.rs#L561-L597","documentation":"The `but discard` command attempted to discard the selected uncommitted changes, but some files were refused by the underlying git operation (typically because they are in conflict or cannot be discarded safely). The CLI reports the exact refused file paths via the `{refused_paths}` list joined with commas so the user knows which changes were left untouched.","triggerScenarios":"Calling `discard()` on a selection of uncommitted changes where `git discard`/gix refuses at least one path — e.g. a file has unresolved merge conflict state, is newly staged/unstaged in a way the discard backend won't reverse, or the worktree state changed between listing and discarding.","commonSituations":"Users select all changes in a conflicted worktree and hit discard; IDE/CLI stale view after files changed on disk; discarding changes to files inside conflicted merge state; race between UI list refresh and the discard call.","solutions":["Inspect the listed refused paths and resolve conflicts manually (e.g. `git checkout -- <path>` or `git restore <path>` once resolved)","Re-run `but status` (or refresh the UI) so the change list matches the current worktree, then discard again","Complete or abort the in-progress merge/rebase (`git merge --abort`) that puts the files in conflict state","Discard the refused files one at a time to isolate which one is problematic"],"exampleFix":"// before: discard everything in one call, failing on any refusal\nlet outcome = discard(ctx, all_paths)?;\n// after: discard individually and report per-path failures\nfor path in paths {\n    if let Err(e) = discard(ctx, vec![path.clone()]) {\n        eprintln!(\"could not discard {}: {e}\", path);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// resolve conflicts first\nlet conflicted: Vec<_> = repo.statuses(None)?.iter().filter(|e| e.status().is_conflicted()).collect();\nif !conflicted.is_empty() {\n    bail!(\"resolve conflicts before discarding: {:?}\", conflicted);\n}","typeGuard":null,"tryCatchPattern":"match discard(ctx, paths) {\n    Err(e) if e.to_string().contains(\"Could not discard all selected changes\") => {\n        let refused = extract_paths(&e.to_string());\n        eprintln!(\"resolve these files manually: {refused}\");\n    }\n    Err(e) => return Err(e),\n    Ok(outcome) => outcome,\n}","preventionTips":["Refresh the change list immediately before discarding to avoid stale paths","Check for merge/rebase conflict state before offering discard","Discard files in small batches so a single refusal doesn't block everything"],"tags":["git","discard","cli"],"backgroundTag":"git-command-failed","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"}