Re: [RFC PATCH 1/1] add -p: support discarding hunks with 'x'
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- Mar 25, 2026, 15:44 UTC
- Message-ID
- <CALnO6CD15Tcs+Sr7XDO0eB3KSC7RT2oawTiSpUGdrQkfbPJQtg@mail.gmail.com>
- In-Reply-To
- <20260325075055.354709-2-luizedc1@gmail.com>
On Wed, Mar 25, 2026 at 3:53 AM Luiz Campos <luizedc1@gmail.com> wrote:
Show 13 quoted lines
> > When using `git add -p`, users can stage or skip hunks, > but cannot discard unwanted changes from the working tree. > > Introduce a new 'x' action to discard the current hunk by > reverse-applying it. > > This idea was suggested in a previous mailing list discussion: > https://lore.kernel.org/git/X%2FiFCo0bXLR%2BLZXs@coredump.intra.peff.net/t/#m0576e6f3c6375e11cc4693b9dca3c1fc57baadd0 > > Feedback is very welcome. > > Signed-off-by: Luiz Campos <luizedc1@gmail.com>
One feature the Fugitive Git client for Vim supports is to discard hunks; when it does so, it also prints a message explaining how to recover the hunk if you need it.
I think it writes the file as a blob to Git's database before restoring from the index.
I'm not suggesting Git copy this necessarily, but we might want to consider how to help folks when they lose a hunk they didn't mean to. If it's never been in the index, it can be impossible to recover!
PS How different is this from "git restore -p" ?
-- D. Ben Knoble