{"thread":{"id":"22405","subject":"[PATCH v2.1 3/5] Documentation: reset: describe new \"--keep\" option","startedAt":"2010-01-27T05:52:34Z","lastAt":"2010-01-27T05:52:34Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":2,"patchTotal":5},"messages":[{"id":"132746","messageId":"20100127055235.6328.21579.chriscool@tuxfamily.org","threadId":"22405","inReplyTo":null,"subject":"[PATCH v2.1 3/5] Documentation: reset: describe new \"--keep\" option","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2010-01-27T05:52:34Z","receivedAt":"2010-01-27T05:52:34Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"and give an example to show how it can be used.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-reset.txt |   47 ++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 46 insertions(+), 1 deletions(-)\n\nThis is to replace patch \"[PATCH v2 3/5]\" (in the \"reset --keep\" series),\nwhich has some grammar/spelling problems.\n\ndiff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt\nindex 168db08..b9ecd49 100644\n--- a/Documentation/git-reset.txt\n+++ b/Documentation/git-reset.txt\n@@ -8,7 +8,7 @@ git-reset - Reset current HEAD to the specified state\n SYNOPSIS\n --------\n [verse]\n-'git reset' [--mixed | --soft | --hard | --merge] [-q] [<commit>]\n+'git reset' [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]\n 'git reset' [-q] [<commit>] [--] <paths>...\n 'git reset' --patch [<commit>] [--] [<paths>...]\n \n@@ -52,6 +52,11 @@ OPTIONS\n \tand updates the files that are different between the named commit\n \tand the current commit in the working tree.\n \n+--keep::\n+\tResets the index to match the tree recorded by the named commit,\n+\tbut keep changes in the working tree. Aborts if the reset would\n+\tchange files that are already modified in the working tree.\n+\n -p::\n --patch::\n \tInteractively select hunks in the difference between the index\n@@ -93,6 +98,7 @@ in the index and in state D in HEAD.\n \t\t\t\t--mixed  A       D     D\n \t\t\t\t--hard   D       D     D\n \t\t\t\t--merge (disallowed)\n+\t\t\t\t--keep  (disallowed)\n \n       working index HEAD target         working index HEAD\n       ----------------------------------------------------\n@@ -100,6 +106,7 @@ in the index and in state D in HEAD.\n \t\t\t\t--mixed  A       C     C\n \t\t\t\t--hard   C       C     C\n \t\t\t\t--merge (disallowed)\n+\t\t\t\t--keep   A       C     C\n \n       working index HEAD target         working index HEAD\n       ----------------------------------------------------\n@@ -107,6 +114,7 @@ in the index and in state D in HEAD.\n \t\t\t\t--mixed  B       D     D\n \t\t\t\t--hard   D       D     D\n \t\t\t\t--merge  D       D     D\n+\t\t\t\t--keep  (disallowed)\n \n       working index HEAD target         working index HEAD\n       ----------------------------------------------------\n@@ -114,6 +122,7 @@ in the index and in state D in HEAD.\n \t\t\t\t--mixed  B       C     C\n \t\t\t\t--hard   C       C     C\n \t\t\t\t--merge  C       C     C\n+\t\t\t\t--keep   B       C     C\n \n       working index HEAD target         working index HEAD\n       ----------------------------------------------------\n@@ -121,6 +130,7 @@ in the index and in state D in HEAD.\n \t\t\t\t--mixed  B       D     D\n \t\t\t\t--hard   D       D     D\n \t\t\t\t--merge (disallowed)\n+\t\t\t\t--keep  (disallowed)\n \n       working index HEAD target         working index HEAD\n       ----------------------------------------------------\n@@ -128,6 +138,7 @@ in the index and in state D in HEAD.\n \t\t\t\t--mixed  B       C     C\n \t\t\t\t--hard   C       C     C\n \t\t\t\t--merge  B       C     C\n+\t\t\t\t--keep   B       C     C\n \n \"reset --merge\" is meant to be used when resetting out of a conflicted\n merge. Any mergy operation guarantees that the work tree file that is\n@@ -138,6 +149,14 @@ between the index and the work tree, then it means that we are not\n resetting out from a state that a mergy operation left after failing\n with a conflict. That is why we disallow --merge option in this case.\n \n+\"reset --keep\" is meant to be used when removing some of the last\n+commits in the current branch while keeping changes in the working\n+tree. If there could be conflicts between the changes in the commit we\n+want to remove and the changes in the working tree we want to keep,\n+the reset is disallowed. That's why it is disallowed if there are both\n+changes between the working tree and HEAD, and between HEAD and the\n+target.\n+\n The following tables show what happens when there are unmerged\n entries:\n \n@@ -147,6 +166,7 @@ entries:\n \t\t\t\t--mixed  X       B     B\n \t\t\t\t--hard   B       B     B\n \t\t\t\t--merge  B       B     B\n+\t\t\t\t--keep  (disallowed)\n \n       working index HEAD target         working index HEAD\n       ----------------------------------------------------\n@@ -154,6 +174,7 @@ entries:\n \t\t\t\t--mixed  X       A     A\n \t\t\t\t--hard   A       A     A\n \t\t\t\t--merge  A       A     A\n+\t\t\t\t--keep   X       A     A\n \n X means any state and U means an unmerged index.\n \n@@ -325,6 +346,30 @@ $ git add frotz.c                           <3>\n <2> This commits all other changes in the index.\n <3> Adds the file to the index again.\n \n+Keep changes in working tree while discarding some previous commits::\n++\n+Suppose you are working on something and you commit it, and then you\n+continue working a bit more, but now you think that what you have in\n+your working tree should be in another branch that has nothing to do\n+with what you commited previously. You can start a new branch and\n+reset it while keeping the changes in your work tree.\n++\n+------------\n+$ git tag start\n+$ git branch branch1\n+$ edit\n+$ git commit ...                            <1>\n+$ edit\n+$ git branch branch2                        <2>\n+$ git reset --keep start                    <3>\n+------------\n++\n+<1> This commits your first edits in branch1.\n+<2> This creates branch2, but unfortunately it contains the previous\n+commit that you don't want in this branch.\n+<3> This removes the unwanted previous commit, but this keeps the\n+changes in your working tree.\n+\n Author\n ------\n Written by Junio C Hamano <gitster@pobox.com> and Linus Torvalds <torvalds@osdl.org>\n-- \n1.6.6.1.557.g77031\n"}]}