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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 12, 2026, 22:31 UTC
Message-ID
<xmqqse4jug1e.fsf@gitster.g>
In-Reply-To
<21db84ba-3894-23e9-9f17-ceeafb1990c2@gmx.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 22 quoted lines
>> 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.

I agree that functionality to cover the "classify three kinds of changes in the working tree files, update both index and working tree files" is a good thing to have.

I did not, and still do not, think "git add -p" is a good place to add a feature to munge working tree files, though.

IOW, what I am lamenting is that we have add/checkout each having "-p" options, and as separate commands, the user cannot handle three kinds of changes in the working tree files without switching between these two commands.

 - changes that we want to add to the index for the next commit
   (you tell [y] to add -p)
 - changes that we want to leave in the working tree files
   (you tell [n] to add -p)
 - changes that we want to get rid of from the working tree files
   (you tell [y] to checkout -p)

The ancient patch deserved to be discarded, simply because "if we are adding it to 'add -p', what about 'checkout p'?" is a valid question.

But the need to have a single command that can deal with the three kinds without exiting does exist. It might be beneficial to widen our horizon to also consider if it would help us to include stash into the mix. It may give two choices to handle the second class of changes, making them into four categories, i.e.

 - changes that we want to add to the index for the next commit
 - changes that we want to stash away from the working tree files
 - changes that we want to leave in the working tree files
 - changes that we want to get rid of from the working tree files
Previous: Junio C Hamano
Message 15 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.