Skip to content

Commit 7cc4276

Browse files
committed
forgit: Add interactive git discard command
Currently, unstaging and reverting uncommitted changes requires running separate git reset and git checkout commands. This is error-prone and lacks the interactive file selection that other forgit commands provide, forcing users to manually specify files or risk discarding unintended changes. Add forgit_discard (gdc) command that combines unstaging and reverting into a single interactive operation. This provides a safer workflow by showing a preview of changes before discarding and allows selective file-by-file confirmation, consistent with forgit's design philosophy of making destructive operations more deliberate. Signed-off-by: Javier Tia <floss@jetm.me>
1 parent d99f7f0 commit 7cc4276

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

README.md

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

145145
- **Interactive `git reset HEAD <file>` selector** (`grh`)
146146

147+
- **Interactive `git discard` (unstage and revert) selector** (`gdc`)
148+
147149
- **Interactive `git checkout <file>` selector** (`gcf`)
148150

149151
- **Interactive `git checkout <branch>` selector** (`gcb`)
@@ -222,6 +224,7 @@ forgit_diff=gd
222224
forgit_show=gso
223225
forgit_add=ga
224226
forgit_reset_head=grh
227+
forgit_discard=gdc
225228
forgit_ignore=gi
226229
forgit_attributes=gat
227230
forgit_checkout_file=gcf
@@ -286,6 +289,7 @@ These are passed to the according `git` calls.
286289
| `gd` | `FORGIT_DIFF_GIT_OPTS` |
287290
| `gso` | `FORGIT_SHOW_GIT_OPTS` |
288291
| `grh` | `FORGIT_RESET_HEAD_GIT_OPTS` |
292+
| `gdc` | `FORGIT_DISCARD_GIT_OPTS` |
289293
| `gcf` | `FORGIT_CHECKOUT_FILE_GIT_OPTS` |
290294
| `gcb` | `FORGIT_CHECKOUT_BRANCH_GIT_OPTS`, `FORGIT_CHECKOUT_BRANCH_BRANCH_GIT_OPTS` |
291295
| `gsw` | `FORGIT_SWITCH_BRANCH_GIT_OPTS` |
@@ -346,6 +350,7 @@ Customizing fzf options for each command individually is also supported:
346350
| `gd` | `FORGIT_DIFF_FZF_OPTS` |
347351
| `gso` | `FORGIT_SHOW_FZF_OPTS` |
348352
| `grh` | `FORGIT_RESET_HEAD_FZF_OPTS` |
353+
| `gdc` | `FORGIT_DISCARD_FZF_OPTS` |
349354
| `gcf` | `FORGIT_CHECKOUT_FILE_FZF_OPTS` |
350355
| `gcb` | `FORGIT_CHECKOUT_BRANCH_FZF_OPTS` |
351356
| `gsw` | `FORGIT_SWITCH_BRANCH_FZF_OPTS` |
@@ -396,6 +401,7 @@ export FORGIT_LOG_FZF_OPTS='
396401
| `FORGIT_FULLSCREEN_CONTEXT` | lines of diff context in full-screen mode | 10 |
397402
| `FORGIT_DIR_VIEW` | command used to preview directories | `tree` if available, otherwise `find` |
398403
| `FORGIT_CLEAN_LIST_FILES_OPTS` | arguments passed to `git ls-files` together with `--others` to determine which files are shown when invoking `forgit clean` | |
404+
| `FORGIT_DISCARD_CONFIRM` | Prompt for confirmation before discarding changes | |
399405

400406
# 📦 Optional dependencies
401407

0 commit comments

Comments
 (0)