{"thread":{"id":"15325","subject":"Unexpected behaviour with git stash save --keep-index?","startedAt":"2008-09-01T23:14:10Z","lastAt":"2008-09-02T07:45:16Z","messageCount":6,"participants":["Jonas Flodén","SZEDER Gábor","Karl Hasselström"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"89458","messageId":"B1185033-36D7-4504-92A3-6F75B6CE90DF@gmail.com","threadId":"15325","inReplyTo":null,"subject":"Unexpected behaviour with git stash save --keep-index?","fromName":"Jonas Flodén","fromEmail":"jonas.floden@gmail.com","sentAt":"2008-09-01T23:14:10Z","receivedAt":"2008-09-01T23:14:10Z","isPatch":false,"sender":{"key":"jonas.floden@gmail.com","avatar":null},"body":"Hello all,\n\nwhile I was using StGit for the first time and used git stash to split\nthe changes into different patches I noticed that git stash save -- \nkeep-index\nwill stash also the changes that are already in the index. This was  \nunexpected\natleast to me but maybe someone can explain why it's correct.\n\nThe following sequence should illustrate the problem. Notice how both  \nthe\nb and c are popped from the stash.\n\ngit init\necho a > test.txt\ngit add test.txt\ngit commit -m \"a\"\necho b >> test.txt\ngit add test.txt\necho c >> test.txt\ngit stash save --keep-index\ngit commit -m \"b\"\ngit checkout -b new_branch HEAD^\ngit stash pop\ngit diff\n\nAlso maybe someone could someone recommend a way to split an unclean  \nworking dir\ninto several patches/commits?\n\nWith regards\n\nJonas\n"},{"id":"89468","messageId":"20080902012804.GB6739@neumann","threadId":"15325","inReplyTo":"B1185033-36D7-4504-92A3-6F75B6CE90DF@gmail.com","subject":"Re: Unexpected behaviour with git stash save --keep-index?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-09-02T01:28:04Z","receivedAt":"2008-09-02T01:28:04Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Tue, Sep 02, 2008 at 01:14:10AM +0200, Jonas Flodén wrote:\n> while I was using StGit for the first time and used git stash to split\n> the changes into different patches I noticed that git stash save -- \n> keep-index\n> will stash also the changes that are already in the index. This was  \n> unexpected\n> atleast to me but maybe someone can explain why it's correct.\nA plain 'git stash [save]' means \"save all local modifications and\nclear both the index and the working tree\".\n\n'git stash save --keep-index' means \"save all local modifications and\nremove all modifications from the working tree that are not in the\nindex\".  This differs substantially from \"save only those\nmodifications that are not in the index, and then remove them from the\nworking tree\".\n\n> Also maybe someone could someone recommend a way to split an unclean  \n> working dir\n> into several patches/commits?\nThe workflow described at the end of stash's man page (under 'Testing\npartial commits') works well for me.\n\n(Heh, I have just looked that section up, and noticed that the\nformatting is broken and some comments are missing from the man page.\nI will send out a patch in a minute.)\n\nRegards,\nGábor\n"},{"id":"89469","messageId":"1220319324-23012-1-git-send-email-szeder@ira.uka.de","threadId":"15325","inReplyTo":"20080902012804.GB6739@neumann","subject":"[PATCH] Documentation: fix disappeared lines in 'git stash' manpage","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-09-02T01:35:24Z","receivedAt":"2008-09-02T01:35:24Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Asciidoc removes lines starting with a dot when creating manpages.\nSince those lines were comments in use case examples showing shell\ncommands, preceed those lines with a hash sign.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n Documentation/git-stash.txt |   14 +++++++-------\n 1 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 49e2296..cdf3cf1 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -159,7 +159,7 @@ perform a pull, and then unstash, like this:\n +\n ----------------------------------------------------------------\n $ git pull\n-...\n+# ...\n file foobar not up to date, cannot merge.\n $ git stash\n $ git pull\n@@ -174,7 +174,7 @@ make a commit to a temporary branch to store your changes away, and\n return to your original branch to make the emergency fix, like this:\n +\n ----------------------------------------------------------------\n-... hack hack hack ...\n+# ... hack hack hack ...\n $ git checkout -b my_wip\n $ git commit -a -m \"WIP\"\n $ git checkout master\n@@ -182,18 +182,18 @@ $ edit emergency fix\n $ git commit -a -m \"Fix in a hurry\"\n $ git checkout my_wip\n $ git reset --soft HEAD^\n-... continue hacking ...\n+# ... continue hacking ...\n ----------------------------------------------------------------\n +\n You can use 'git-stash' to simplify the above, like this:\n +\n ----------------------------------------------------------------\n-... hack hack hack ...\n+# ... hack hack hack ...\n $ git stash\n $ edit emergency fix\n $ git commit -a -m \"Fix in a hurry\"\n $ git stash apply\n-... continue hacking ...\n+# ... continue hacking ...\n ----------------------------------------------------------------\n \n Testing partial commits::\n@@ -203,13 +203,13 @@ more commits out of the changes in the work tree, and you want to test\n each change before committing:\n +\n ----------------------------------------------------------------\n-... hack hack hack ...\n+# ... hack hack hack ...\n $ git add --patch foo            # add just first part to the index\n $ git stash save --keep-index    # save all other changes to the stash\n $ edit/build/test first part\n $ git commit foo -m 'First part' # commit fully tested change\n $ git stash pop                  # prepare to work on all other changes\n-... repeat above five steps until one commit remains ...\n+# ... repeat above five steps until one commit remains ...\n $ edit/build/test remaining parts\n $ git commit foo -m 'Remaining parts'\n ----------------------------------------------------------------\n-- \n1.6.0.1.171.gaaac\n"},{"id":"89470","messageId":"1220319901-23733-1-git-send-email-szeder@ira.uka.de","threadId":"15325","inReplyTo":"1220319324-23012-1-git-send-email-szeder@ira.uka.de","subject":"[PATCH] Documentation: minor cleanup in a use case in 'git stash' manual","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-09-02T01:45:01Z","receivedAt":"2008-09-02T01:45:01Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"There is no need to explicitly pass the file to be committed to 'git\ncommit', because it's contents is already in the index.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n\n  Ah, and one more small change in stash docs.\n\n Documentation/git-stash.txt |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex cdf3cf1..f91368c 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -207,7 +207,7 @@ each change before committing:\n $ git add --patch foo            # add just first part to the index\n $ git stash save --keep-index    # save all other changes to the stash\n $ edit/build/test first part\n-$ git commit foo -m 'First part' # commit fully tested change\n+$ git commit -m 'First part'     # commit fully tested change\n $ git stash pop                  # prepare to work on all other changes\n # ... repeat above five steps until one commit remains ...\n $ edit/build/test remaining parts\n-- \n1.6.0.1.171.gaaac\n"},{"id":"89484","messageId":"g9ilut$n58$1@ger.gmane.org","threadId":"15325","inReplyTo":"20080902012804.GB6739@neumann","subject":"Re: Unexpected behaviour with git stash save --keep-index?","fromName":"Jonas Flodén","fromEmail":"jonas.floden@gmail.com","sentAt":"2008-09-02T06:20:13Z","receivedAt":"2008-09-02T06:20:13Z","isPatch":false,"sender":{"key":"jonas.floden@gmail.com","avatar":null},"body":"SZEDER Gábor wrote:\n > 'git stash save --keep-index' means \"save all local modifications and\n >  remove all modifications from the working tree that are not in the\n > index\".  This differs substantially from \"save only those\n > modifications that are not in the index, and then remove them from\n > the working tree\".\n >\n\nThanks for the explanation. It seemed strange first but now I know\nwhy it does that.\n\n >> Also maybe someone could someone recommend a way to split an\n >> unclean working dir into several patches/commits?\n > The workflow described at the end of stash's man page (under 'Testing\n >  partial commits') works well for me.\n >\n\nThanks. What about the case when I already have a number of existing\npatches/commits and want to split the working dir into them.\n\nRegards,\nJonas\n"},{"id":"89487","messageId":"20080902074516.GA5402@diana.vm.bytemark.co.uk","threadId":"15325","inReplyTo":"B1185033-36D7-4504-92A3-6F75B6CE90DF@gmail.com","subject":"Re: Unexpected behaviour with git stash save --keep-index?","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-09-02T07:45:16Z","receivedAt":"2008-09-02T07:45:16Z","isPatch":false,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-09-02 01:14:10 +0200, Jonas Flodén wrote:\n\n> while I was using StGit for the first time\n[...]\n> Also maybe someone could someone recommend a way to split an unclean\n> working dir into several patches/commits?\n\nThis is what I usually do:\n\n  1. Create a new StGit patch with all the changes.\n\n  2. Pop that patch.\n\n  3. View the patch in an emacs diff-mode buffer, and repeatedly\n\n       a. apply one or more hunks, and\n\n       b. create a new patch with just those changes\n\n     until no more changes remain.\n\nAnother way to do it would be to\n\n  1. Use e.g. git-gui to stage the changes you want in your first\n     patch.\n\n  2. Make an StGit patch out of just that (with e.g. stg new and stg\n     refresh --index).\n\n  3. If the worktree is still dirty, go to step 1.\n\nA third method I usually make use of is to commit very often while\ndeveloping, and periodically clump these microcommits together into\nlarger commits. This sidesteps the whole problem of splitting up a\ncommit into pieces, which can be quite a chore if splitting on hunk\nboundaries isn't enough. (stg coalesce will turn two or more smaller\npatches into one large patch for you. And I'm pretty sure git-rebase\n--interactive has some equivalent functions.)\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}