From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Christian Couder <chriscool@tuxfamily.org>, git@vger.kernel.org
Subject: git reset --keep (Re: What's cooking in git.git (Mar 2010, #01; Wed, 03))
Date: Fri, 5 Mar 2010 10:25:21 -0600 [thread overview]
Message-ID: <20100305162521.GA25120@progeny.tock> (raw)
In-Reply-To: <7vk4trlhim.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> Do you think I finally understood what "reset --keep" is about?
Probably. :) Let me take the opportunity to give some examples of what
I am hoping to use it for, to see if I am crazy.
> Nah, what was I thinking. If I rephrase your side note <2> and <3> a
> little bit, everything makes sense. Perhaps like so:
>
> <2> In the ideal world, you could have realized that the earlier
> commit did not belong to the new topic when you created and switched
> to branch2 (i.e. "git checkout -b branch2 start"), but nobody is
> perfect.
>
> <3> But you can use "reset --keep" to remove the unwanted commit after
> you switched to "branch2".
>
> And it becomes very clear that "reset --keep" is a sensible way to recover
> from this mistake. No need to do "read-tree -m -u" followed by "reset"
> anymore.
Yes, this (recovery from a wrong choice of starting commit for a new
branch) makes sense. Here are some other planned uses:
1. Helping people new to git.
A person not very familiar with git comes to me asking how to undo
the last couple of commits. After a quick conversation, it becomes
clear that the commits in question were not pushed out to any public
repository and that this person does not feel it would be useful to
publish the problem commits.
Currently, I would have to advise such a person to use
git reset --hard HEAD^^
I would prefer to recommend
git reset --keep HEAD^^
because if there are uncommitted changes then it will give a "needs
update" message (right?) and I can help the person to deal with it.
2. Splitting up a huge patch.
Suppose I have a huge patch consisting of several unrelated changes
applied to the work tree but not commited. I want to split it into
logical changes, commiting each one, and when I am done I will use a
loop reading from git rev-list to test all the resulting commits
automatically. A workflow for this looks something like the
following:
git checkout -b series1
git add -p
git commit
git add -p
git commit
git checkout -b series2 appropriate-base
git add -p
git commit
...
Having 'git reset --keep' available would add some flexibility:
* As you mentioned, reset --keep would let me recover from 'git
checkout -b' to the wrong commit.
* As in example 1, if some part of the patch turns out to be a
bad idea after all, I can try to discard it.
A 'git stash' might be worth avoiding in some cases because it touches
unrelated files, which means wasted time rebuilding everything.
3. Keeping unrelated extra changes around.
Suppose I am Linus, and I keep on forgetting to update the version
number in a file named version.h or something. So I update it in
advance as soon as I remember, but I do not commit the change or
register it in the index because it is not time yet.
Then in almost every instance when I would have normally used
'reset --hard', I should use 'reset --keep' instead. The only
exception is when I am mean “screw it all, reset to a completely
known state”; in that case, I will have to update version.h by hand
again.
next prev parent reply other threads:[~2010-03-05 16:25 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-04 0:02 What's cooking in git.git (Mar 2010, #01; Wed, 03) Junio C Hamano
2010-03-04 0:36 ` Adam Simpkins
2010-03-04 8:26 ` Björn Gustavsson
2010-03-04 18:26 ` Junio C Hamano
2010-03-04 12:09 ` Tay Ray Chuan
2010-03-04 18:26 ` Junio C Hamano
2010-03-04 21:42 ` Junio C Hamano
2010-03-05 0:49 ` Junio C Hamano
2010-03-05 16:25 ` Jonathan Nieder [this message]
2010-03-05 21:08 ` git reset --keep (Re: What's cooking in git.git (Mar 2010, #01; Wed, 03)) Christian Couder
2010-03-05 17:32 ` What's cooking in git.git (Mar 2010, #01; Wed, 03) Christian Couder
2010-03-04 22:21 ` Thomas Rast
2010-03-05 1:30 ` Mark Lodato
2010-03-05 1:32 ` Mark Lodato
2010-03-05 3:23 ` Junio C Hamano
2010-03-06 0:39 ` [PATCH] Add tests for git format-patch --to and format.to config option Miklos Vajna
2010-03-06 2:21 ` Junio C Hamano
2010-03-06 21:06 ` [PATCH] format-patch --to: overwrite format.to contents, don't append it Miklos Vajna
2010-03-07 0:06 ` [PATCH] Add tests for git format-patch --to and format.to config option Stephen Boyd
2010-03-07 1:20 ` Miklos Vajna
2010-03-07 3:42 ` Junio C Hamano
2010-03-07 9:43 ` Stephen Boyd
2010-03-07 18:38 ` Junio C Hamano
2010-03-07 21:33 ` [PATCH 0/4] format-patch and send-email ignoring config settings Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 0/3] " Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 1/3] format-patch: use a string_list for headers Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 2/3] format-patch: add --no-cc, --no-to, and --no-add-headers Stephen Boyd
2010-03-07 22:46 ` [PATCHv2 3/3] send-email: add --no-cc, --no-to, and --no-bcc Stephen Boyd
2010-03-09 2:44 ` [PATCH 0/4] format-patch and send-email ignoring config settings Junio C Hamano
2010-03-07 21:33 ` [PATCH 1/4] send-email: actually add bcc headers Stephen Boyd
2010-03-07 21:53 ` Stephen Boyd
2010-03-07 21:33 ` [PATCH 2/4] format-patch: use a string_list for headers Stephen Boyd
2010-03-07 21:44 ` Erik Faye-Lund
2010-03-07 21:54 ` Stephen Boyd
2010-03-07 22:13 ` Johannes Schindelin
2010-03-07 21:33 ` [PATCH 3/4] format-patch: add --no-cc, --no-to, and --no-add-headers Stephen Boyd
2010-03-07 21:33 ` [PATCH 4/4] send-email: add --no-cc, --no-to, and --no-bcc Stephen Boyd
2010-03-10 3:53 ` [PATCH] Add tests for git format-patch --to and format.to config option Steven Drake
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=20100305162521.GA25120@progeny.tock \
--to=jrnieder@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).