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

[RFC PATCH 0/1] add -p: support discarding hunks

From
LCLuiz Campos <luizedc1@gmail.com>
Date
Mar 25, 2026, 07:50 UTC
Message-ID
<20260325075055.354709-1-luizedc1@gmail.com>
Hi,
This is an RFC for adding a 'discard hunk' action to `git add -p`.

Currently, when using `git add -p`, users can stage or skip hunks, but cannot discard unwanted changes directly from the working tree. This often leads to repeatedly skipping the same hunks across multiple passes.

This patch introduces a new 'x' action to discard the current hunk by reverse-applying it to the working tree.

This idea was previously discussed on the mailing list: https://lore.kernel.org/git/X%2FiFCo0bXLR%2BLZXs@coredump.intra.peff.net/t/#m0576e6f3c6375e11cc4693b9dca3c1fc57baadd0

Open questions:
- Should discard happen immediately or be deferred until patch application?
- Are there edge cases involving overlapping hunks or edited hunks?
Feedback is very welcome.

Thanks, Luiz

Luiz Campos (1):
  [RFC PATCH 0/1] add -p: support discarding hunks with 'x'
 Documentation/git-add.adoc |   7 +-
 add-patch.c                | 137 ++++++++++++++++++++++++++++---------
 t/t3701-add-interactive.sh |  58 ++++++++++------
 3 files changed, 149 insertions(+), 53 deletions(-)
-- 
2.43.0
Next: Luiz Campos
Message 1 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.