Thomas Rast <> writes:

> Mina Almasry <> 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':

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".
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to