git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Thomas Rast <trast@student.ethz.ch>,
	Nicolas Sebrecht <nicolas.s.dev@gmx.fr>,
	Matthieu Moy <Matthieu.Moy@imag.fr>,
	git@vger.kernel.org, Kevin Ballard <kevin@sb.org>,
	Yann Dirson <dirson@bertin.fr>, Eric Raible <raible@nextest.com>,
	Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH] Documentation: suggest "reset --keep" to undo a commit
Date: Fri, 21 Jan 2011 09:34:26 -0800	[thread overview]
Message-ID: <7voc7ap3dp.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20110121073730.GA26276@burratino> (Jonathan Nieder's message of "Fri\, 21 Jan 2011 01\:37\:30 -0600")

Jonathan Nieder <jrnieder@gmail.com> writes:

> When one's only goal is to move from one commit to another, reset
> --keep is simply better than reset --hard, since it preserves local
> changes in the index and worktree when easy and errors out without
> doing anything when not.  Update the two "how to remove commits"
> examples in this vein.  "reset --hard" is still explained in a later
> example about cleaning up during a merge.

I agree with the first sentence but I do not think its conclusion would
lead to changes to "how to _remove_ commits".  The examples were written
in contexts (explanatory text <$n>) where hard makes sense, and the
context needs tweaking to make keep makes more sense than hard does.

For example, the first one's original sequence is this:

    $ git branch topic/wip
    $ git reset --hard HEAD~3
    $ git checkout topic/wip

The text explains the motivation behind these series of commands in <1>
but it has one untold assumption behind it; the user did the review to
reach the conclusion that the recent changes are premature after fully
committing (i.e. the working tree is clean).  That is why "hard" worked
just fine.

But the user could do the reviewing and thinking with some local changes
still in the working tree (they are incredients for the fourth commit yet
to be made) and decide to branch at that point.  The description in <1>
needs to be updated to hint that there can be uncommitted changes, e.g.

	You have worked for some time, made a few commits, and may have
	uncommitted changes.  After reviewing the current state, you
	realized that ...

Using --keep may help the user do so, but only if the local changes do not
conflict with the changes in the recent commits to be discarded, right?

    Side note: Regardless of any of the above, the section header needs to
    be updated---it is not "Undo *A* commit", we are excluding three from
    the current branch.

By the way, a more natural way to do this would actually be:

    $ git checkout -b topic/wip
    $ git branch -f @{-1} HEAD~3

or using the stash:

    $ git stash ;# save local changes
    $ git branch topic/wip ;# and mark the tip before rewinding
    $ git reset --hard HEAD~3 ;# you could say --keep here too
    $ git checkout topic/wip ;# and then continue
    $ git stash pop ;# with the local changes

The branch/reset/checkout sequence itself, either with hard or keep, looks
more like a contrived example to show "reset" than the best way to solve
the problem in the scenario presented there.  Probably we would want to
drop this one altogether, or keep the scenario and explain the best
solution in somewhere else (e.g. tutorial).

> @@ -163,7 +163,7 @@ Undo commits permanently::
>  +
>  ------------
>  $ git commit ...
> -$ git reset --hard HEAD~3   <1>
> +$ git reset --keep HEAD~3   <1>
>  ------------
>  +
>  <1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad

Please tell a story where keep makes more sense than hard by enhancing the
explanatory text <1> associated with this section.  The current text says
that the three topmost commit representing what you have recently worked
so far are all unwanted, strongly hinting that hard is more appropriate
thing to do than keep, which is not what we want if we are changing the
example to use keep.

It would be sufficient to just hint that the uncommitted changes that you
have in your working tree are unrelated to what these three commits wanted
to do (e.g. you always keep small changes around, such as debugging
printf's and a change to the version string in Makefile---you do not
intend to commit them and they are unrelated to the commits you are
discarding), and you do want to keep them around if you can.

  reply	other threads:[~2011-01-21 17:35 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-10 13:08 Black smoke from git rebase -i exec Ævar Arnfjörð Bjarmason
2010-08-10 13:37 ` Matthieu Moy
2010-08-10 13:57   ` Ævar Arnfjörð Bjarmason
2010-08-10 14:12     ` Johannes Sixt
2010-08-10 14:16       ` Ævar Arnfjörð Bjarmason
2010-08-10 15:05         ` Matthieu Moy
2010-08-10 15:17           ` [PATCH 1/2 (fix broken test)] rebase -i: add exec command to launch a shell command Matthieu Moy
2010-08-11 18:31             ` Junio C Hamano
2010-08-12  7:47               ` Matthieu Moy
2011-01-16  1:59             ` [PATCH 0/2] rebase -i: in-editor documentation nits Jonathan Nieder
2011-01-16  2:01               ` [PATCH 1/2] rebase -i: reword in-editor documentation of "exec" Jonathan Nieder
2011-01-16 10:27                 ` Matthieu Moy
2011-01-18 15:05                   ` Junio C Hamano
2011-01-20 20:09                   ` Jonathan Nieder
2011-01-20 20:59                     ` Junio C Hamano
2011-01-21  0:36                       ` [PATCH 1/2 v2] rebase -i: clarify " Jonathan Nieder
2011-01-21  6:59                         ` Matthieu Moy
2011-01-21  7:47                           ` Jonathan Nieder
2011-01-21 10:43                             ` Matthieu Moy
2011-01-16  2:02               ` [PATCH 2/2] rebase -i: explain how to discard all commits Jonathan Nieder
2011-01-20 19:39                 ` [PATCH 2/2] " Nicolas Sebrecht
2011-01-20 19:57                   ` Jonathan Nieder
2011-01-20 20:08                     ` Nicolas Sebrecht
2011-01-20 20:34                       ` Thomas Rast
2011-01-20 21:28                         ` Junio C Hamano
2011-01-21  7:04                           ` Johannes Schindelin
2011-01-21  7:37                             ` [PATCH] Documentation: suggest "reset --keep" to undo a commit Jonathan Nieder
2011-01-21 17:34                               ` Junio C Hamano [this message]
2011-01-21 19:14                                 ` Jonathan Nieder
2011-01-21 20:28                                   ` Junio C Hamano
2011-01-21 16:51                             ` [PATCH 2/2] Re: rebase -i: explain how to discard all commits Junio C Hamano
2011-01-21 17:05                               ` Matthieu Moy
2011-01-21 17:57                                 ` Joshua Jensen
2011-01-21 18:37                                   ` [PATCH] Documentation: do not treat reset --keep as a special case Jonathan Nieder
2011-01-21 20:35                                     ` Junio C Hamano
2011-01-26  7:33                                   ` [PATCH 2/2] Re: rebase -i: explain how to discard all commits Jay Soffian
2011-01-23 20:10                               ` Johannes Schindelin
2010-08-10 15:17           ` [PATCH 2/2] test-lib: user-friendly alternatives to test [-d|-f|-e] Matthieu Moy

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7voc7ap3dp.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=Matthieu.Moy@imag.fr \
    --cc=chriscool@tuxfamily.org \
    --cc=dirson@bertin.fr \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=kevin@sb.org \
    --cc=nicolas.s.dev@gmx.fr \
    --cc=raible@nextest.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).