From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Couder Subject: [PATCH v2 3/5] Documentation: reset: describe new "--keep" option Date: Tue, 19 Jan 2010 05:25:59 +0100 Message-ID: <20100119042602.4510.8666.chriscool@tuxfamily.org> References: <20100119042404.4510.48855.chriscool@tuxfamily.org> Cc: git@vger.kernel.org, Linus Torvalds , Johannes Schindelin , Stephan Beyer , Daniel Barkalow , Jakub Narebski , Paolo Bonzini , Johannes Sixt , Stephen Boyd , Andreas Schwab , Daniel Convissor To: Junio C Hamano X-From: git-owner@vger.kernel.org Tue Jan 19 05:24:30 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.50) id 1NX5dk-0006y9-J9 for gcvg-git-2@lo.gmane.org; Tue, 19 Jan 2010 05:24:28 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754903Ab0ASEYW (ORCPT ); Mon, 18 Jan 2010 23:24:22 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752822Ab0ASEYW (ORCPT ); Mon, 18 Jan 2010 23:24:22 -0500 Received: from smtp3-g21.free.fr ([212.27.42.3]:53650 "EHLO smtp3-g21.free.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754774Ab0ASEYU (ORCPT ); Mon, 18 Jan 2010 23:24:20 -0500 Received: from smtp3-g21.free.fr (localhost [127.0.0.1]) by smtp3-g21.free.fr (Postfix) with ESMTP id 12635818079; Tue, 19 Jan 2010 05:23:59 +0100 (CET) Received: from bureau.boubyland (gre92-7-82-243-130-161.fbx.proxad.net [82.243.130.161]) by smtp3-g21.free.fr (Postfix) with ESMTP id DE84D81806B; Tue, 19 Jan 2010 05:23:56 +0100 (CET) X-git-sha1: aa61ae6a2df79e3a9eb337f1dd66f00fa315b7d3 X-Mailer: git-mail-commits v0.5.2 In-Reply-To: <20100119042404.4510.48855.chriscool@tuxfamily.org> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: and give an example to show how it can be used. Signed-off-by: Christian Couder --- Documentation/git-reset.txt | 47 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 46 insertions(+), 1 deletions(-) diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 168db08..90239f5 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -8,7 +8,7 @@ git-reset - Reset current HEAD to the specified state SYNOPSIS -------- [verse] -'git reset' [--mixed | --soft | --hard | --merge] [-q] [] +'git reset' [--mixed | --soft | --hard | --merge | --keep] [-q] [] 'git reset' [-q] [] [--] ... 'git reset' --patch [] [--] [...] @@ -52,6 +52,11 @@ OPTIONS and updates the files that are different between the named commit and the current commit in the working tree. +--keep:: + Resets the index to match the tree recorded by the named commit, + but keep changes in the working tree. Aborts if the reset would + change files that are already modified in the working tree. + -p:: --patch:: Interactively select hunks in the difference between the index @@ -93,6 +98,7 @@ in the index and in state D in HEAD. --mixed A D D --hard D D D --merge (disallowed) + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -100,6 +106,7 @@ in the index and in state D in HEAD. --mixed A C C --hard C C C --merge (disallowed) + --keep A C C working index HEAD target working index HEAD ---------------------------------------------------- @@ -107,6 +114,7 @@ in the index and in state D in HEAD. --mixed B D D --hard D D D --merge D D D + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -114,6 +122,7 @@ in the index and in state D in HEAD. --mixed B C C --hard C C C --merge C C C + --keep B C C working index HEAD target working index HEAD ---------------------------------------------------- @@ -121,6 +130,7 @@ in the index and in state D in HEAD. --mixed B D D --hard D D D --merge (disallowed) + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -128,6 +138,7 @@ in the index and in state D in HEAD. --mixed B C C --hard C C C --merge B C C + --keep B C C "reset --merge" is meant to be used when resetting out of a conflicted merge. Any mergy operation guarantees that the work tree file that is @@ -138,6 +149,14 @@ between the index and the work tree, then it means that we are not resetting out from a state that a mergy operation left after failing with a conflict. That is why we disallow --merge option in this case. +"reset --keep" is meant to be used when remove some of the last +commits in the current branch while keep changes in the working tree. +If there could be conflicts between the changes in the commit we want +to remove and the changes in the working tree we want to keep, the +reset is disallowed. That's why it is disallowed if there are both +changes between the working tree and HEAD, and between HEAD and the +target. + The following tables show what happens when there are unmerged entries: @@ -147,6 +166,7 @@ entries: --mixed X B B --hard B B B --merge B B B + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -154,6 +174,7 @@ entries: --mixed X A A --hard A A A --merge A A A + --keep X A A X means any state and U means an unmerged index. @@ -325,6 +346,30 @@ $ git add frotz.c <3> <2> This commits all other changes in the index. <3> Adds the file to the index again. +Keep changes in working tree while discarding some previous commits:: ++ +Suppose you are working on something and you commit it, and then you +continue working a bit more, but now you think that what you have in +your working tree should be in another branch that has nothing to do +with what you commited previously. You can start a new branch and +reset it while keeping the changes in your work tree. ++ +------------ +$ git tag start +$ git branch branch1 +$ edit +$ git commit ... <1> +$ edit +$ git branch branch2 <2> +$ git reset --keep start <3> +------------ ++ +<1> This commits your first edits in branch1. +<2> This creates branch2, but unfortunately it contains the previous +commit that you don't want in this branch. +<3> This removes the unwanted previous commit, but this keeps the +changes in your working tree. + Author ------ Written by Junio C Hamano and Linus Torvalds -- 1.6.6.271.gc8799