Skip to content

Commit ea508d8

Browse files
committed
forgit: Add interactive git discard selector
Currently, discarding uncommitted changes requires two separate git commands: git reset HEAD to unstage files and git restore to revert working tree changes. This two-step process is error-prone and cumbersome when dealing with multiple files, especially since there is no built-in interactive selector for this combined operation. Add forgit_discard (gdc) command that combines unstage and restore into a single atomic operation with interactive file selection. This streamlines the workflow for discarding changes while maintaining the safety and visibility benefits of interactive selection through fzf. The command includes a warning in documentation about its destructive nature to prevent accidental data loss. Signed-off-by: Javier Tia <floss@jetm.me>
1 parent 2fa47a9 commit ea508d8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ If you're having issues after updating, and commands such as `forgit::add` or al
146146

147147
- **Interactive `git restore <file>` selector** (`grs`)
148148

149+
- **Interactive `git discard <file>` selector** (`gdc`)
150+
151+
Combines `git reset HEAD` (unstage) and `git restore` (revert) into a single operation,
152+
fully discarding all changes for selected files back to their committed state.
153+
154+
> **Warning:** This permanently discards uncommitted changes with no way to recover them.
155+
149156
- **Interactive `git checkout <file>` selector** (`gcf`)
150157

151158
- **Interactive `git checkout <branch>` selector** (`gcb`)
@@ -225,6 +232,7 @@ forgit_show=gso
225232
forgit_add=ga
226233
forgit_reset_head=grh
227234
forgit_restore=grs
235+
forgit_discard=gdc
228236
forgit_ignore=gi
229237
forgit_attributes=gat
230238
forgit_checkout_file=gcf
@@ -290,6 +298,7 @@ These are passed to the according `git` calls.
290298
| `gso` | `FORGIT_SHOW_GIT_OPTS` |
291299
| `grh` | `FORGIT_RESET_HEAD_GIT_OPTS` |
292300
| `grs` | `FORGIT_RESTORE_GIT_OPTS` |
301+
| `gdc` | `FORGIT_DISCARD_GIT_OPTS` |
293302
| `gcf` | `FORGIT_CHECKOUT_FILE_GIT_OPTS` |
294303
| `gcb` | `FORGIT_CHECKOUT_BRANCH_GIT_OPTS`, `FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS` |
295304
| `gsw` | `FORGIT_SWITCH_BRANCH_GIT_OPTS` |
@@ -351,6 +360,7 @@ Customizing fzf options for each command individually is also supported:
351360
| `gso` | `FORGIT_SHOW_FZF_OPTS` |
352361
| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` |
353362
| `grs` | `FORGIT_RESTORE_FZF_OPTS` |
363+
| `gdc` | `FORGIT_DISCARD_FZF_OPTS` |
354364
| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` |
355365
| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` |
356366
| `gsw` | `FORGIT_SWITCH_BRANCH_FZF_OPTS` |

0 commit comments

Comments
 (0)