git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 1/1] add -p: support discarding hunks with 'x'

From
LCLuiz Eduardo Campos <luizedc1@gmail.com>
Date
Mar 25, 2026, 17:04 UTC
Message-ID
<CAN+A6TuhiC9U==QvuMXtnTHtwzSMh1fSe12kxqj3iy03jF-Cxg@mail.gmail.com>
In-Reply-To
<CALnO6CD15Tcs+Sr7XDO0eB3KSC7RT2oawTiSpUGdrQkfbPJQtg@mail.gmail.com>
Hi Ben,
Thanks for the feedback!

(Sending this message again because I had not configured my email client to send it plain text, so I apologize if you received duplicated content)

> 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.

That’s a great point. I hadn’t considered recoverability in this initial version. Storing the discarded hunk as a blob (or otherwise making it recoverable) seems like a useful safety measure.

> If it's never been in the index, it can be impossible to recover!

Agreed — this is probably something that should be addressed before considering this feature complete.

> PS How different is this from "git restore -p" ?

My understanding is that `git restore -p` already allows discarding changes interactively, but it requires a separate pass. The goal here was to allow discarding during `git add -p`, so users can decide what to do with each hunk in a single pass.

That said, I’m not yet sure whether integrating this into `add -p` is the best approach, or if this should be handled differently.

Thanks again for the insights!
Luiz

Em qua., 25 de mar. de 2026 às 12:44, D. Ben Knoble <ben.knoble@gmail.com> escreveu:

Show 32 quoted lines
>
> On Wed, Mar 25, 2026 at 3:53 AM Luiz Campos <luizedc1@gmail.com> wrote:
> >
> > 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
Previous: D. Ben KnobleNext: Phillip Wood
Message 4 of 10 in “add -p: support discarding hunks”
  1. 0/1 add -p: support discarding hunksLuiz Campos, Mar 25, 2026
  2. 1/1 add -p: support discarding hunks with 'x'Luiz Campos, Mar 25, 2026
  3. D. Ben KnobleMar 25, 2026
  4. Luiz Eduardo CamposMar 25, 2026
  5. Phillip WoodMar 25, 2026
  6. Luiz Eduardo CamposMar 25, 2026
  7. Johannes SchindelinMar 25, 2026
  8. Luiz Eduardo CamposMar 25, 2026
  9. Junio C HamanoMar 25, 2026
  10. Luiz Eduardo CamposMar 25, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.