fix(review-diff): discard a fully-staged file back to HEAD (#2318) - #2332
Open
sinelaw wants to merge 1 commit into
Open
fix(review-diff): discard a fully-staged file back to HEAD (#2318)#2332sinelaw wants to merge 1 commit into
sinelaw wants to merge 1 commit into
Conversation
sinelaw
force-pushed
the
claude/upbeat-maxwell-8ohgr0
branch
from
June 22, 2026 18:39
2eea4f3 to
da0a545
Compare
File-level Discard (`D`) in Review Diff ran `git checkout -- <path>`, which only rewrites the working tree from the index. When a file's change is entirely staged (clean working tree), that command is a no-op, yet the status bar still reported `Discarded: <file>` — telling the user an irreversible discard succeeded while the staged change remained in the index, on disk, and in the diff. Reset the file all the way back to its committed state with `git checkout HEAD -- <path>`, which restores both the index entry and the working tree to HEAD, so staged and unstaged edits alike are dropped. Also honor the command's exit code: only claim "Discarded" when it actually succeeded, otherwise surface "Discard failed" rather than a false success. Adds an e2e test that stages a change (clean working tree), discards the file via `D`, and asserts the change disappears from the review diff and that neither the working tree nor the index retains it. The test times out against the old `git checkout -- <path>` path. Fixes #2318
sinelaw
force-pushed
the
claude/upbeat-maxwell-8ohgr0
branch
from
July 17, 2026 11:54
da0a545 to
6685926
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2318.
In Review Diff, the file-level Discard action (
D) rangit checkout -- <path>, which only rewrites the working tree from the index. When a file's change is entirely staged (clean working tree), that command is a no-op — yet the status bar still reportedDiscarded: <file>, telling the user an irreversible discard succeeded while the staged change remained in the index, on disk, and in the diff.Fix
git checkout HEAD -- <path>, which restores both the index entry and the working tree to HEAD, so staged and unstaged edits alike are dropped (the obvious meaning of the "this cannot be undone" discard dialog).Discardedwhen it actually succeeded; otherwise surfaceDiscard failed: …instead of a false success.The untracked-file branch (
rm) is unchanged.Testing
test_issue2318_discard_fully_staged_file_reverts_to_head: stages a change so the working tree is clean, opens Review Diff, discards the file viaD, and asserts the change disappears from the diff and that neither the working tree nor the index retains it. The test times out against the oldgit checkout -- <path>path (the change is never discarded) and passes with the fix.tsc --strict) passes.Manual validation
Built the
freshbinary and reproduced the issue's exact scenario in tmux (commit a file, stage a one-line change,Review Diff→D→ confirm):Discarded.Discarded: calc.py,git status --shortis empty,git diff --cached --quietreturns 0, andcalc.pyon disk is back to its committed contents.https://claude.ai/code/session_01FqagsaYk1AERmbNY5GbnK2
Generated by Claude Code