Add interactive git restore and git discard commands#489
Open
Add interactive git restore and git discard commands#489
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new interactive forgit_discard command (aliased as gdc) that combines unstaging and reverting uncommitted changes into a single operation. This fills a gap in forgit's workflow by providing a safe, interactive way to discard staged changes with preview and optional confirmation, consistent with forgit's design philosophy of making destructive operations more deliberate.
Changes:
- Added
_forgit_discard()function with preview and interactive file selection for discarding staged changes - Integrated the new command across all shell plugins (bash, zsh, fish) and completion systems
- Added comprehensive test coverage for the new functionality
- Updated documentation with usage examples and configuration options
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| bin/git-forgit | Implements the core discard functionality with _forgit_discard(), _forgit_git_discard(), and _forgit_discard_preview() functions |
| tests/discard.test.sh | Adds test suite covering empty state, tracked file restoration, new file handling, and unstaging behavior |
| forgit.plugin.zsh | Registers forgit::discard() function and gdc alias for zsh |
| conf.d/forgit.plugin.fish | Registers abbreviation for fish shell |
| completions/git-forgit.fish | Adds completion support for fish shell |
| completions/git-forgit.bash | Adds completion support for bash |
| completions/_git-forgit | Adds completion support for zsh |
| README.md | Documents the new command in features list and configuration tables |
| LICENSE | Updates copyright year to 2026 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wfxr
reviewed
Feb 5, 2026
ea508d8 to
7f90257
Compare
Currently there is no interactive way to selectively discard modifications to working tree files. Users must either manually type file paths with git restore or use git checkout, which is the older discouraged syntax. This makes it cumbersome to selectively discard changes when reviewing multiple modified files. Add _forgit_restore function that provides an fzf-based selector for modified files with diff preview. This follows the same pattern as existing forgit commands like reset_head and checkout_file, allowing users to interactively review diffs before discarding changes. The command is exposed as 'grs' alias and integrated with shell completion systems across bash/zsh/fish. Signed-off-by: Javier Tia <floss@jetm.me>
Currently the restore functionality lacks automated tests, making it difficult to verify correctness during refactoring and increasing the risk of regressions. Without tests, developers cannot confidently modify the restore behavior or ensure edge cases are handled properly. Add a complete test suite covering core restore scenarios including modified files, untracked files, mixed staged/unstaged changes, and renamed files. These tests validate that restore correctly reverts working tree changes while preserving staged content and ignoring untracked files, ensuring the command behaves consistently with Git's restore semantics. Signed-off-by: Javier Tia <floss@jetm.me>
Currently, users must run two separate commands to completely revert changes: reset HEAD to unstage files, then restore to discard working tree modifications. This two-step workflow is error-prone and inefficient, especially when reverting multiple files interactively. Introduce a discard command that combines unstage and restore into a single interactive operation. This provides a safer and more streamlined way to abandon uncommitted changes through the familiar fzf-based file selector, matching the workflow of existing forgit commands like add and restore while preventing the common mistake of unstaging without actually reverting the changes. Signed-off-by: Javier Tia <floss@jetm.me>
The git-forgit discard feature previously lacked automated test coverage, making it difficult to verify correct behavior across different scenarios and prevent regressions during refactoring or enhancements. Add a full test suite covering critical discard workflows: empty repository state, unstaged modifications, staged changes, mixed staging states, committed renames, and argument passthrough. These tests validate that discard correctly restores files to their committed state regardless of staging status or file history. Signed-off-by: Javier Tia <floss@jetm.me>
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.
forgit: Add interactive restore command for discarding changes
Currently there is no interactive way to selectively discard
modifications to working tree files. Users must either manually type
file paths with git restore or use git checkout, which is the older
discouraged syntax. This makes it cumbersome to selectively discard
changes when reviewing multiple modified files.
Add _forgit_restore function that provides an fzf-based selector for
modified files with diff preview. This follows the same pattern as
existing forgit commands like reset_head and checkout_file, allowing
users to interactively review diffs before discarding changes. The
command is exposed as 'grs' alias and integrated with shell completion
systems across bash/zsh/fish.
forgit: Add discard command for unstage and restore
Currently, users must run two separate commands to completely revert
changes: reset HEAD to unstage files, then restore to discard working
tree modifications. This two-step workflow is error-prone and
inefficient, especially when reverting multiple files interactively.
Introduce a discard command that combines unstage and restore into a
single interactive operation. This provides a safer and more streamlined
way to abandon uncommitted changes through the familiar fzf-based file
selector, matching the workflow of existing forgit commands like add and
restore while preventing the common mistake of unstaging without
actually reverting the changes.
Check list
Description
Type of change
Test environment