Skip to content

Add interactive git restore and git discard commands#489

Open
jetm wants to merge 4 commits intowfxr:mainfrom
jetm:forgit-discard
Open

Add interactive git restore and git discard commands#489
jetm wants to merge 4 commits intowfxr:mainfrom
jetm:forgit-discard

Conversation

@jetm
Copy link

@jetm jetm commented Feb 2, 2026

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

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have added unit tests for my code
  • I have made corresponding changes to the documentation

Description

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Test
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jetm jetm force-pushed the forgit-discard branch 2 times, most recently from ea508d8 to 7f90257 Compare February 11, 2026 23:12
@jetm jetm changed the title Add interactive git discard command Add interactive git restore and git discard commands Feb 11, 2026
jetm added 2 commits February 11, 2026 17:14
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>
jetm added 2 commits February 11, 2026 17:16
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants