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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 15, 2012, 18:11 UTC
Message-ID
<7vvcgk58le.fsf@alter.siamese.dyndns.org>
In-Reply-To
<87txw41okl.fsf@thomas.inf.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 14 quoted lines
> Mina Almasry <almasry.mina@hotmail.com> writes:
>
>> 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
That is a blast from the past.

Why is saying "git checkout ." too much work, after "add -p" that you excluded the debugging cruft?

I actually do this for extra safety, though:
	git add -p ;# add everything but exclude debug cruft
	git diff ;# make really sure that this shows only garbage
	git diff | git apply -R ;# and get rid of that garbage

primarily because I can take the "git diff" output in the second step to a file, remove the hunk that I accidentally forgot to add in the "add -p" stage, and "apply -R" to remove only the cruft. After doing so, "git diff" will show the important-but-forgotten bit, and I can choose to add it to the next commit, or I can choose to leave it in the working tree for a future commit after the current index is committed.

But the above is a tangent side-note to show possibly a better way to work, not about adding new operations to "add -p".

Previous: Thomas RastNext: Junio C Hamano
Message 3 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.