Repository navigation
feat: discard changes per file, hunk or line, after confirming - #12
Merged
Merged
Conversation
This was referenced Nov 1, 2026
Merged
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.
What this changes
You can now throw away changes you do not want, at three levels:
Since none of this can be undone, each discard first asks, naming what will be lost ("Discard the unstaged changes to file.txt?", "Delete notes.tmp? Git does not track it.", "Discard this hunk of list.txt?"). The confirm button stays disabled while git is busy, so a click is never dropped.
Smaller things that came with it:
In the core this is one new
Op::DiscardLines, which runsgit apply --reverseon the working tree with the patchFileDiff::patchalready builds for unstaging. The dialog (Confirm) is generic, so the next roadmap item (confirming a hard reset, deleting an unmerged branch, force push) can reuse it.How it is tested
crates/core/tests/repo.rs,discard_single_lines_from_the_working_tree: discards a removed line, an added line and an added last line without a newline from a real repository, and checks that a staged change in the same file stays staged.crates/app/src/tests.rs, through the accessibility tree:discard_a_changed_file_once_confirmed: Cancel keeps the change, Discard restores the file.discarding_an_open_untracked_file_deletes_it_and_closes_it: the file is deleted and its diff closes without an error.discard_single_lines_and_hunks: discards one picked line, then checks Escape only closes the question, then discards the hunk.Each new app test fails without the change it covers (checked by taking the change out).
The app tests now run their repositories with
core.autocrlf=false, like the core tests, andsettlealso waits for a reload the watcher starts in the meantime (macOS reports changes late). The first CI run failed on both.Tried by hand in the release build on Linux: deleting an untracked file, discarding a removed line, a hunk and a whole open file, and Escape in the dialog.
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepassIt adds as little code as the change needs, and removes what it makes unnecessary
Nothing in it comes from GitKraken or another closed-source client (see CONTRIBUTING.md)