Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: Can we do better than "git checkout/add -p"
Date: Wed, 12 Aug 2026 15:31:41 -0700	[thread overview]
Message-ID: <xmqqse4jug1e.fsf@gitster.g> (raw)
In-Reply-To: <21db84ba-3894-23e9-9f17-ceeafb1990c2@gmx.de> (Johannes Schindelin's message of "Wed, 12 Aug 2026 10:40:08 +0200 (CEST)")

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

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


      parent reply	other threads:[~2026-08-12 22:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07  4:02 Can we do better than "git checkout/add -p" Junio C Hamano
2026-08-07  7:38 ` Christian Couder
2026-08-07 11:24 ` D. Ben Knoble
2026-08-07 15:50   ` Junio C Hamano
2026-08-07 20:12     ` D. Ben Knoble
2026-08-07 20:26       ` Junio C Hamano
2026-08-10  6:03     ` Patrick Steinhardt
2026-08-10  7:26       ` Stefan Haller
2026-08-10  8:45         ` Patrick Steinhardt
2026-08-10 15:23         ` Junio C Hamano
2026-08-11  5:06           ` Patrick Steinhardt
2026-08-12  8:40 ` Johannes Schindelin
2026-08-12 21:44   ` Jeff King
2026-08-12 22:35     ` Junio C Hamano
2026-08-12 22:31   ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqse4jug1e.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox