git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Mina Almasry <almasry.mina@hotmail.com>
Cc: Thomas Rast <trast@student.ethz.ch>, git@vger.kernel.org
Subject: Re: Feature request - discard hunk in add --patch mode
Date: Wed, 15 Aug 2012 14:51:57 -0700	[thread overview]
Message-ID: <7vfw7n4yde.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <BLU0-SMTP112EF6B9308C55734C4F10293B60@phx.gbl> (Mina Almasry's message of "Wed, 15 Aug 2012 16:58:08 -0400")

Mina Almasry <almasry.mina@hotmail.com> writes:

> On 12-08-15 02:46 PM, Junio C Hamano wrote:
> ...
>> Please forget this question.  A better way in the form of "stash -p"
>> was suggested in the old thread to get rid of debug cruft in the
>> tree before an "add -p" session (or during a series of "add -p"
>> sessions).
>>
>> So is this still an issue?
>>
> I read most of the thread, and I do think it still is. Here are my 2 cents:
>
> 1. The alternative commands aren't nearly as time efficient:
>     - git checkout . is fast and awesome, but you can't use it if, for
> example, you have to maintain a dirty         working tree
>     - git (stash|reset|checkout) -p make you go through (all|most) of
> the hunks you have to hunt down             those 2 lines that say
> "echo 'This line is runningantoeuhaoeuaoae'"

You have to do that _at least once_ anyway, as there is no other way
for Git to tell which one is debugging cruft and which one is the
real change you value without you telling it.  Will return to the
topic later.

> 2. All of the safety concerns can be alleviated with the right
> interface.

There are three safety concerns I raised in the original thread.
Among them, I do not think

 (1) new user may mistake "undo" to be something safe; and
 (2) experts will continue making typo between "y" and "u"

are the primary risks of the original patch Thomas pointed out.  

A much bigger problem with the approach is (3) letting "add" touch
the working tree breaks the world model.  Both experts and newbies
alike, people have learned that "git add" will never clobber what
they have in the working tree and rely on that promise.

And your key assignment, command renaming or extra prompting do not
change this fundamental issue at all.

Let's step back a bit, and define the problem we are solving.

Suppose you have changes in your working tree that are worth
multiple commits, debugging aid, and uncommittable WIP.  You want to
create multiple commits, possibly giving each of them the final
testing before committing, and want to end up with the WIP (plus
possibly the debugging aid, as that may still help your WIP) in your
working tree.

Do we agree that the goal of the discussion of this thread is to
make that process simple, safe, efficient and easy?

Now, back when the original patch by Pierre was proposed, it indeed
was cumbersome.  You could sift things through by "add -p" to build
the first commit in the index, commit, and iterate.  In each round,
"add -p" step had to skip the same debugging aid and WIP over and
over again.  If you wanted to give the result of "git add -p" a
final test before committing, "stash save -k" would give you the
state you would be committing, but it isn't easy to reintroduce only
the debugging aid to the working tree.

Since then "stash -p" was added to our toolchest.  So theoretically,
we should be able to do something like this:

    # start from N-commit worth of change, debug and WIP
    git stash save -p debug ;# stash away only the debugging aid
    # now we have only N-commit worth of change and WIP
    git stash save -p wip ;# stash away WIP

Then after that, you need N round of "git add -p && git commit".

Now, with what we have already, can we also give final testing
before committing?  Each round may now start with:

    git add -p ;# prepare the index for the next commit
    git stash save -k ;# save away the changes for later commits

and at this point, your working tree and the index has what you are
about to commit.  If we can apply the "debugging aid" stash we
created earlier to the working tree, that would allow you to test
the state you are about to commit with your debugging aid.  The
command to do so may be

    git stash apply stash@{2}

Once you are satisfied, you can reset this change out of your
working tree with "checkout .", and then "git commit" to record what
is in the index.

And then you can "git stash pop" to bring back the remainder of
N-commit series worth of changes.  You are ready to continue to the
next round.

Once you created N-commit series, you will still have two stash
entries, one "debug" and one "wip".  You should be able to resurrect
"wip" with

    git stash pop

just fine, but there is a little problem after this step.  Because
"git stash [apply|pop]" does not want to work on a dirty working
tree, starting from this state just after popping "wip" stash, you
cannot "git stash pop" to have both WIP changes and debugging aid to
the working tree.

A topic to improve "stash [apply/pop]" to allow it may be a valid
and useful thing to do.

As an approximation, without changing any of the current tools,
however, you should be able to do this after creating N-commit
series following the above procedure.

	git stash pop ;# resurrect "wip" to the working tree.
        git add -u ;# and add that to the index temporarily
        git stash pop ;# resurrect "debug" to the working tree as well.
	git reset ;# then match the index to HEAD

That will mix the WIP and debug again in your working tree.

Why you would want to mix them together, after sifting debug and wip
using "add -p" already, is a different issue, though (there are
valid scenarios why you would want to do so, and there are valid
cases why you do not have to bother).

So is this still an issue?

  reply	other threads:[~2012-08-15 21:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-15  8:36 Feature request - discard hunk in add --patch mode Mina Almasry
2012-08-15  9:39 ` Thomas Rast
2012-08-15 18:11   ` Junio C Hamano
2012-08-15 18:46     ` Junio C Hamano
2012-08-15 20:58       ` Mina Almasry
2012-08-15 21:51         ` Junio C Hamano [this message]
2012-08-23  3:32         ` Mina Almasry

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=7vfw7n4yde.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=almasry.mina@hotmail.com \
    --cc=git@vger.kernel.org \
    --cc=trast@student.ethz.ch \
    /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;
as well as URLs for NNTP newsgroup(s).