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

Re: Can we do better than "git checkout/add -p"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 12, 2026, 08:40 UTC
Message-ID
<21db84ba-3894-23e9-9f17-ceeafb1990c2@gmx.de>
In-Reply-To
<xmqq8q6ih924.fsf@gitster.g>
Hi Junio,
On Thu, 6 Aug 2026, Junio C Hamano wrote:
Show 23 quoted lines
> I am doing more "git checkout -p" (selective revert of local changes
> out of the working tree files) these days, as well as "git add -p"
> (selective adding of local changes to the index), and what I often
> wish is to have _both_ as possible options in a single session.
> That is, the local changes in my working tree often fall into three
> categories.  (1) One that is clearly good, (2) one that is good but
> not yet ready, and (3) one that is bogus and should be discarded.
> 
> "git checkout -p" is a way that is very suitable for (3), while "git
> add -p" is a way to deal with (1).  To (2), I say "no" in "git add
> -p", but there is no easy way from "git add -p" to say that the hunk
> is (3).
> 
> My current workaround is not to use "git checkout -p" and instead
> (e)dit an undesirable hunk into a no-op hunk.  This is serviceable,
> but with two caveats:
> 
>  - The underlying 'apply' machinery does not see a truly no-op,
>    context-only hunk.  You'd need to pretend removing an existing
>    line and adding the same line back.
> 
>  - (e)dit applies the edited hunk right away without giving the user
>    a chance to proofread and approve or reedit.

I, too, often find myself in exactly that kind of need. That's why I was *so* disappointed when https://lore.kernel.org/git/20260325075055.354709-1-luizedc1@gmail.com/ was shot down unceremoniously. I still think that would be a good addition. I even opened https://github.com/gitgitgadget/git/issues/1828 and sketched https://github.com/git/git/compare/master...dscho:git:add-p-stash-mode to the same extent.

Maybe it is time to revisit that verdict, and see whether there is really no way to accept that clearly needed functionality.

Ciao, Johannes

Previous: Patrick SteinhardtNext: Jeff King
Message 12 of 15 in “Can we do better than "git checkout/add -p"”
  1. Junio C HamanoAug 7, 2026
  2. Christian CouderAug 7, 2026
  3. D. Ben KnobleAug 7, 2026
  4. Junio C HamanoAug 7, 2026
  5. D. Ben KnobleAug 7, 2026
  6. Junio C HamanoAug 7, 2026
  7. Patrick SteinhardtAug 10, 2026
  8. Stefan HallerAug 10, 2026
  9. Patrick SteinhardtAug 10, 2026
  10. Junio C HamanoAug 10, 2026
  11. Patrick SteinhardtAug 11, 2026
  12. Johannes SchindelinAug 12, 2026
  13. Jeff KingAug 12, 2026
  14. Junio C HamanoAug 12, 2026
  15. Junio C HamanoAug 12, 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.