[UX] git restore -p: confusing prompt after failed hunk edit

From: Lino Haupt <hidden>
Date: 2025-09-08 18:11:28

Dear Git developers,

I'd like to report a small UX issue in the interactive patch editor
used by 'git restore -p' (and, to a lesser extent, 'git add -p').

Short description:
If a manual hunk edit fails, Git currently prints:
   Your edited hunk does not apply. Edit again (saying "no"
   discards!) [y/n]?

The word "discard" here is confusingly close to the normal prompt of
`git restore -p`:
   (2/10) Discard this hunk from worktree [y,n,q,a,d,K,j,J,g,/,e,p,?]?

Environment:
- git version: 2.50.1 (NixOS)

Reproduction:
1. Run 'git restore -p' in a repository with unstaged changes.
2. When shown a hunk, type 'e' to edit the hunk manually.
3. Make an edit that causes the patch not to apply (e.g., remove
    required context), then save and exit.

Actual behavior:
Git prints:
   Your edited hunk does not apply. Edit again (saying "no"
   discards!) [y/n]?

The normal 'restore -p' prompt uses the same word "discard" for the
hunk itself, e.g.:
   (2/10) Discard this hunk from worktree [y,n,...]?

Why this is confusing:
In the failure prompt, "discard" refers to discarding the edit, while
in the normal prompt it refers to discarding the hunk. This made me
hesitate about whether answering 'n' would discard my edit (keeping the
original hunk) or discard the hunk itself.

'git add -p' shows the same failure prompt. Its normal prompt says
   Stage this hunk [y,n,...]?
So the ambiguity is weaker but still present.

Suggestion:
Consider clarifying the failure prompt.
Any of the following would remove the ambiguity:

A (minimal change):
   Your edited hunk does not apply. Edit again (saying "no" discards
   the edit!) [y/n]?

B (explicit menu-style):
   Your edited hunk does not apply. y: edit again; n: discard the edit
   [y/n]?

C (shortest, avoids "discard" altogether):
   Your edited hunk does not apply. y: edit again; n: cancel edit [y/n]?

Rationale:
Point out what exactly is discarded (or cancelled).
This makes it explicit what 'n' does and avoids collision with the
normal "Discard this hunk..." wording in 'git restore -p'. It should
help users who quickly scan prompts.

Thanks for all the great work on Git!

Best regards,
Lino Haupt



Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help