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

Junio C Hamano <[email protected]>
Newsgroups org.kernel.vger.git
Message-ID <[email protected]>
Johannes Schindelin <[email protected]> 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/[email protected]/
> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.