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

Re: Feature request - discard hunk in add --patch mode

From
Thomas Rast <trast@student.ethz.ch>
Date
Aug 15, 2012, 09:39 UTC
Message-ID
<87txw41okl.fsf@thomas.inf.ethz.ch>
In-Reply-To
<BLU0-SMTP37070ADBEC060E1EA15944693B60@phx.gbl>
Mina Almasry <almasry.mina@hotmail.com> writes:
Show 7 quoted lines
> I frequently stage files using git add --patch command and I almost 
> always come across debug code I want to discard, but there is no option 
> for that in the prompt. The result is that I have to run an extra 
> command after the dialogue ends.
>
> I would like to add a feature to allow users to discard hunks using a 
> command like r! or d!

This has come up before, and actually led to the introduction of 'checkout -p' and 'reset -p':

  http://thread.gmane.org/gmane.comp.version-control.git/123854

Judging by the '!' above, you are already aware that this is a dangerous option that needs some safeguards. I imagine that would largely account for Junio's safety concerns. So you could pick up from the general direction of Pierre's post, and try to work out something.

However, life has become rather more complicated since 2009. Whatever you do also needs to fit nicely with checkout/reset/stash -p. The first two also take commit arguments, resulting in a total of seven modes of operation, defined in %patch_modes.

I imagine one good angle of attack would be to proceed as follows:
* Optionally make add--interactive.perl more aware of what the patches
  say.  Ideally there would be a way to reverse the direction of a diff
  (or otherwise manipulate it) in the program itself, instead of having
  to decide this when fetching the patches.
* Change things so that the actions in %patch_modes are a hunk property
  instead of a global state.  Of course the actual mode still needs to
  be global state.  Not all actions should be possible in all modes;
  figure out a clean way to implement this.
* Design commands in some modes that switch to another mode, and/or set
  another action than the default in the current mode.

Note that r! commands need to also work in singlekey mode, where the 'r' is read immediately and you would have to read for another (confirmation) key to get the '!'.

Good luck!
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Mina AlmasryNext: Junio C Hamano
Message 2 of 7 in “Feature request - discard hunk in add --patch mode”
  1. Mina AlmasryAug 15, 2012
  2. Thomas RastAug 15, 2012
  3. Junio C HamanoAug 15, 2012
  4. Junio C HamanoAug 15, 2012
  5. Mina AlmasryAug 15, 2012
  6. Junio C HamanoAug 15, 2012
  7. Mina AlmasryAug 23, 2012

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.