{"thread":{"id":"50942","subject":"[BUG] git stash --keep-index undeletes file","startedAt":"2019-04-16T18:04:09Z","lastAt":"2019-04-16T21:59:51Z","messageCount":4,"participants":["Christian Vetter","Thomas Gummerer"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"373983","messageId":"1555437849815.60450@rasenplanscher.info","threadId":"50942","inReplyTo":null,"subject":"[BUG] git stash --keep-index undeletes file","fromName":"Christian Vetter","fromEmail":"christian@rasenplanscher.info","sentAt":"2019-04-16T18:04:05Z","receivedAt":"2019-04-16T18:04:09Z","isPatch":false,"sender":{"key":"christian@rasenplanscher.info","avatar":null},"body":"Steps to reproduce\n+ mkdir git-stash-test\n+ cd git-stash-test\n+ git init\n+ touch file\n+ git add file\n+ git commit -m init\n+ git rm file\n+ git stash push --keep-index\n \n \nResult: \n`git status` gives this output:\n> On branch master\n> Changes to be committed:\n>   (use \"git reset HEAD <file>...\" to unstage)\n> \n>         deleted:    file\n> \n> Untracked files:\n>   (use \"git add <file>...\" to include in what will be committed)\n> \n>         file\n \n \nExpected: \n`git status` gives this output:\n> On branch master\n> Changes to be committed:\n>   (use \"git reset HEAD <file>...\" to unstage)\n> \n>         deleted:    file\n \n \nVerified on:\n+ Windows 10, git version 2.21.0.windows.1 \n+ Ubuntu 14.04, git version 2.21.0\n"},{"id":"373984","messageId":"20190416184816.GU16414@hank.intra.tgummerer.com","threadId":"50942","inReplyTo":"1555437849815.60450@rasenplanscher.info","subject":"Re: [BUG] git stash --keep-index undeletes file","fromName":"Thomas Gummerer","fromEmail":"t.gummerer@gmail.com","sentAt":"2019-04-16T18:48:16Z","receivedAt":"2019-04-16T18:48:22Z","isPatch":false,"sender":{"key":"t.gummerer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/191004?v=4"},"body":"On 04/16, Christian Vetter wrote:\n> Steps to reproduce\n> + mkdir git-stash-test\n> + cd git-stash-test\n> + git init\n> + touch file\n> + git add file\n> + git commit -m init\n> + git rm file\n> + git stash push --keep-index\n>  \n>  \n> Result: \n> `git status` gives this output:\n> > On branch master\n> > Changes to be committed:\n> >   (use \"git reset HEAD <file>...\" to unstage)\n> > \n> >         deleted:    file\n> > \n> > Untracked files:\n> >   (use \"git add <file>...\" to include in what will be committed)\n> > \n> >         file\n\nI think this is the correct result.  --keep-index keeps the changes\nthat are in the index, in this example that 'file' is deleted, but\nrestores the working tree to 'HEAD', where 'file' existed.  It's now\nshowing up as untracked because Git doesn't know about it.\n\nSimilarly if you just did 'git stash push' without --keep-index,\n'file' would be restored in your working tree, but 'git status' would\nreport the working tree as clean because it would also be restored in\nthe index.\n\n> Expected: \n> `git status` gives this output:\n> > On branch master\n> > Changes to be committed:\n> >   (use \"git reset HEAD <file>...\" to unstage)\n> > \n> >         deleted:    file\n\nThis is what you get before 'git stash push --keep-index'.  Do you\nthink the documentation on '--keep-index' is unclear, and could be\nimproved?  Or why did you think that this is the correct output?\n\n> Verified on:\n> + Windows 10, git version 2.21.0.windows.1 \n> + Ubuntu 14.04, git version 2.21.0\n"},{"id":"373985","messageId":"1555444649793.14863@rasenplanscher.info","threadId":"50942","inReplyTo":"20190416184816.GU16414@hank.intra.tgummerer.com","subject":"Re: [BUG] git stash --keep-index undeletes file","fromName":"Christian Vetter","fromEmail":"christian@rasenplanscher.info","sentAt":"2019-04-16T19:57:25Z","receivedAt":"2019-04-16T19:57:31Z","isPatch":false,"sender":{"key":"christian@rasenplanscher.info","avatar":null},"body":"Thank you, Thomas!\n\nNow that you explained this, I do understand the behaviour, and agree that it is correct.\nWhile this seems to be clear with a deeper understanding of git than I have,\nit might be a good idea to specifically point this out in the docs in the context of `--keep-index`.\nThat would have helped me.\n\nThis does, however, bring me back to a related issue by which I stumbled across this:\nIf, in the given scenario, I run `git stash apply`, the file is not removed. `git status` still outputs this:\n> On branch master\n> Changes to be committed:\n>   (use \"git reset HEAD <file>...\" to unstage)\n>\n>         deleted:    file\n>\n> Untracked files:\n>   (use \"git add <file>...\" to include in what will be committed)\n>\n>         file\n\nCan you explain that behaviour as well?\nThe way I understand it, `git stash push --keep-index; git stash apply` should result in zero change to the output of `git status`.\nWhat am I not getting?\n\n\n________________________________________\nFrom: Thomas Gummerer <t.gummerer@gmail.com>\nSent: Tuesday, April 16, 2019 20:48\nTo: Christian Vetter\nCc: git@vger.kernel.org\nSubject: Re: [BUG] git stash --keep-index undeletes file\n\nOn 04/16, Christian Vetter wrote:\n> Steps to reproduce\n> + mkdir git-stash-test\n> + cd git-stash-test\n> + git init\n> + touch file\n> + git add file\n> + git commit -m init\n> + git rm file\n> + git stash push --keep-index\n>\n>\n> Result:\n> `git status` gives this output:\n> > On branch master\n> > Changes to be committed:\n> >   (use \"git reset HEAD <file>...\" to unstage)\n> >\n> >         deleted:    file\n> >\n> > Untracked files:\n> >   (use \"git add <file>...\" to include in what will be committed)\n> >\n> >         file\n\nI think this is the correct result.  --keep-index keeps the changes\nthat are in the index, in this example that 'file' is deleted, but\nrestores the working tree to 'HEAD', where 'file' existed.  It's now\nshowing up as untracked because Git doesn't know about it.\n\nSimilarly if you just did 'git stash push' without --keep-index,\n'file' would be restored in your working tree, but 'git status' would\nreport the working tree as clean because it would also be restored in\nthe index.\n\n> Expected:\n> `git status` gives this output:\n> > On branch master\n> > Changes to be committed:\n> >   (use \"git reset HEAD <file>...\" to unstage)\n> >\n> >         deleted:    file\n\nThis is what you get before 'git stash push --keep-index'.  Do you\nthink the documentation on '--keep-index' is unclear, and could be\nimproved?  Or why did you think that this is the correct output?\n\n> Verified on:\n> + Windows 10, git version 2.21.0.windows.1\n> + Ubuntu 14.04, git version 2.21.0\n"},{"id":"373990","messageId":"20190416215945.GV16414@hank.intra.tgummerer.com","threadId":"50942","inReplyTo":"1555444649793.14863@rasenplanscher.info","subject":"Re: [BUG] git stash --keep-index undeletes file","fromName":"Thomas Gummerer","fromEmail":"t.gummerer@gmail.com","sentAt":"2019-04-16T21:59:45Z","receivedAt":"2019-04-16T21:59:51Z","isPatch":false,"sender":{"key":"t.gummerer@gmail.com","avatar":"https://avatars.githubusercontent.com/u/191004?v=4"},"body":"[please don't top post on this list]\n\nOn 04/16, Christian Vetter wrote:\n> Thank you, Thomas!\n> \n> Now that you explained this, I do understand the behaviour, and agree that it is correct.\n> While this seems to be clear with a deeper understanding of git than I have,\n> it might be a good idea to specifically point this out in the docs in the context of `--keep-index`.\n> That would have helped me.\n\nOn second thought, I might have been too quick to jump to conclusions\nhere, and might have misunderstood --keep-index myself.  I think what\nyou described here is actually a bug, although it's a pretty long\nstanding one.  So I'm a bit surprised nobody noticed it before.\n\nThanks for reporting it.\n\n> This does, however, bring me back to a related issue by which I stumbled across this:\n> If, in the given scenario, I run `git stash apply`, the file is not removed. `git status` still outputs this:\n> > On branch master\n> > Changes to be committed:\n> >   (use \"git reset HEAD <file>...\" to unstage)\n> >\n> >         deleted:    file\n> >\n> > Untracked files:\n> >   (use \"git add <file>...\" to include in what will be committed)\n> >\n> >         file\n> \n> Can you explain that behaviour as well?\n> The way I understand it, `git stash push --keep-index; git stash apply` should result in zero change to the output of `git status`.\n> What am I not getting?\n\nYour interpretation of what should happen sounds like the right\nbehaviour here, and what actually happens seems incorrect.  I don't\nhave time to dig into this more right now though unfortunately.\n\n> ________________________________________\n> From: Thomas Gummerer <t.gummerer@gmail.com>\n> Sent: Tuesday, April 16, 2019 20:48\n> To: Christian Vetter\n> Cc: git@vger.kernel.org\n> Subject: Re: [BUG] git stash --keep-index undeletes file\n> \n> On 04/16, Christian Vetter wrote:\n> > Steps to reproduce\n> > + mkdir git-stash-test\n> > + cd git-stash-test\n> > + git init\n> > + touch file\n> > + git add file\n> > + git commit -m init\n> > + git rm file\n> > + git stash push --keep-index\n> >\n> >\n> > Result:\n> > `git status` gives this output:\n> > > On branch master\n> > > Changes to be committed:\n> > >   (use \"git reset HEAD <file>...\" to unstage)\n> > >\n> > >         deleted:    file\n> > >\n> > > Untracked files:\n> > >   (use \"git add <file>...\" to include in what will be committed)\n> > >\n> > >         file\n> \n> I think this is the correct result.  --keep-index keeps the changes\n> that are in the index, in this example that 'file' is deleted, but\n> restores the working tree to 'HEAD', where 'file' existed.  It's now\n> showing up as untracked because Git doesn't know about it.\n> \n> Similarly if you just did 'git stash push' without --keep-index,\n> 'file' would be restored in your working tree, but 'git status' would\n> report the working tree as clean because it would also be restored in\n> the index.\n> \n> > Expected:\n> > `git status` gives this output:\n> > > On branch master\n> > > Changes to be committed:\n> > >   (use \"git reset HEAD <file>...\" to unstage)\n> > >\n> > >         deleted:    file\n> \n> This is what you get before 'git stash push --keep-index'.  Do you\n> think the documentation on '--keep-index' is unclear, and could be\n> improved?  Or why did you think that this is the correct output?\n> \n> > Verified on:\n> > + Windows 10, git version 2.21.0.windows.1\n> > + Ubuntu 14.04, git version 2.21.0\n"}]}