{"thread":{"id":"14464","subject":"git stash save --keep-index","startedAt":"2008-07-15T12:31:54Z","lastAt":"2008-07-15T14:50:43Z","messageCount":3,"participants":["Sverre Rabbelier","SZEDER Gábor"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"83389","messageId":"bd6139dc0807150531k4f0a1a4yee2c8ec2b98ee39c@mail.gmail.com","threadId":"14464","inReplyTo":null,"subject":"git stash save --keep-index","fromName":"Sverre Rabbelier","fromEmail":"alturin@gmail.com","sentAt":"2008-07-15T12:31:54Z","receivedAt":"2008-07-15T12:31:54Z","isPatch":false,"sender":{"key":"alturin@gmail.com","avatar":null},"body":"Heya,\n\nI have switched to using next/ recently and have had the chance to try\nout the new '--keep-index' option to 'git stash'. I must say that 'git\nstash save --keep-index' in combination with 'git add -p' followed by\n'e' allows for a really nice workflow where I can split up patches\nvery easily, and test them before committing anything. IIUC the\n'--keep-index' option was added as a response to the request to\nsupport a workflow something like this:\n<hack hack hack>\n$ git add # or -i / -p\n$ git stash save --keep-index\n<test if staged changes are ready to be commited>\n$ git commit\n$ git stash pop\n<lather, rinse, repeat>\n\nBut what happens if in the testing phase you detect that the commit is\nnot ready yet, or even, some of the changes you staged should have\nbeen kept? It would make sense to 'undo' the stash the usual way:\n$ git stash pop\nBut alas, it is not possible to apply on a dirty working directory, so\none has to resort to:\n$ git commit -m \"tmp\"\n$ git stash pop\n$ git reset HEAD^\nNothing too bad surely, but I thought that the '--keep-index' option\nwas exactly to prevent having to do:\n<hack hack hack>\n$ git add # or -i / -p\n$ git commit -m \"tmp\"\n$ git stash save\n<test if now committed changes were indeed ready to be comitted>\nSo the '--keep-index' option eliminates the need for such a temporary\ncommit in the (hopefully) common case where the selected changes were\nindeed good, but we still need it in the case that the changes were\nnot ready / need something from the stashed changes.\n\nAm I missing something here? Or is the only/best solution here to just\nalias 'git commit -m \"tmp\" && git stash pop && git reset HEAD^' to\n'git undo-stash'?\n\nPS: It'd be nice if I could do 'git stash --keep-index' since I\"m used\nto 'git stash' automagically defaulting to 'git stash save'.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"83394","messageId":"20080715142615.GI8224@neumann","threadId":"14464","inReplyTo":"bd6139dc0807150531k4f0a1a4yee2c8ec2b98ee39c@mail.gmail.com","subject":"Re: git stash save --keep-index","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2008-07-15T14:26:15Z","receivedAt":"2008-07-15T14:26:15Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi Sverre,\n\nOn Tue, Jul 15, 2008 at 02:31:54PM +0200, Sverre Rabbelier wrote:\n> <hack hack hack>\n> $ git add # or -i / -p\n> $ git stash save --keep-index\n> <test if staged changes are ready to be commited>\n> $ git commit\n> $ git stash pop\n> <lather, rinse, repeat>\n> \n> But what happens if in the testing phase you detect that the commit is\n> not ready yet, or even, some of the changes you staged should have\n> been kept? It would make sense to 'undo' the stash the usual way:\n> $ git stash pop\n> But alas, it is not possible to apply on a dirty working directory, so\n> one has to resort to:\n> $ git commit -m \"tmp\"\n> $ git stash pop\n> $ git reset HEAD^\nIf there are unstaged changes in the worktree, then yes, 'git stash\napply/pop' will error out complaining about dirty state.  However, if\nthere are changes in the index, but no unstaged changes in the\nworktree, then apply/pop should work (assuming there are no conflicts,\nof course).\n\nSo, you won't need that temporary commit, if you have not modified\nanything or have added all changes to the index since 'git stash\nsave --keep-index'.\n\nGábor\n"},{"id":"83397","messageId":"bd6139dc0807150750u1eff0389x9e4b61822032c65d@mail.gmail.com","threadId":"14464","inReplyTo":"20080715142615.GI8224@neumann","subject":"Re: git stash save --keep-index","fromName":"Sverre Rabbelier","fromEmail":"alturin@gmail.com","sentAt":"2008-07-15T14:50:43Z","receivedAt":"2008-07-15T14:50:43Z","isPatch":false,"sender":{"key":"alturin@gmail.com","avatar":null},"body":"On Tue, Jul 15, 2008 at 4:26 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> If there are unstaged changes in the worktree, then yes, 'git stash\n> apply/pop' will error out complaining about dirty state.  However, if\n> there are changes in the index, but no unstaged changes in the\n> worktree, then apply/pop should work (assuming there are no conflicts,\n> of course).\n>\n> So, you won't need that temporary commit, if you have not modified\n> anything or have added all changes to the index since 'git stash\n> save --keep-index'.\n\nMhhh, ok, I can live with that, thanks!\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}