{"thread":{"id":"56445","subject":"stash push/pop unstages files?","startedAt":"2021-09-05T17:09:22Z","lastAt":"2021-09-05T19:19:37Z","messageCount":4,"participants":["Yuri","Chris Torek"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"434730","messageId":"0e1f7a47-89e3-5f49-663e-bdd3e8efb6e5@rawbw.com","threadId":"56445","inReplyTo":null,"subject":"stash push/pop unstages files?","fromName":"Yuri","fromEmail":"yuri@rawbw.com","sentAt":"2021-09-05T17:09:19Z","receivedAt":"2021-09-05T17:09:22Z","isPatch":false,"sender":{"key":"yuri@rawbw.com","avatar":null},"body":"In one sub-directory I altered some files, added a directory with files \nand added the changes (git add .)\n\nThen I called 'git stash push && git stash pop'.\n\nAfter this the newly added directory remained in the staged status, but \naltered files became unstaged.\n\nIs this an intended behavior?\n\nWhy stash push/pop unstages files? Shouldn't it preserve the directory \nas-is?\n\n\nThanks,\n\nYuri\n\n\n"},{"id":"434731","messageId":"CAPx1Gvc6noTDYPt9x3b4_TE0z8-KE5cB6KQHcn5UL9pi0cKoGg@mail.gmail.com","threadId":"56445","inReplyTo":"0e1f7a47-89e3-5f49-663e-bdd3e8efb6e5@rawbw.com","subject":"Re: stash push/pop unstages files?","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2021-09-05T17:15:51Z","receivedAt":"2021-09-05T17:16:06Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Sun, Sep 5, 2021 at 10:12 AM Yuri <yuri@rawbw.com> wrote:\n> In one sub-directory I altered some files, added a directory with files\n> and added the changes (git add .)\n>\n> Then I called 'git stash push && git stash pop'.\n>\n> After this the newly added directory remained in the staged status, but\n> altered files became unstaged.\n>\n> Is this an intended behavior?\n\nYes.\n\n> Why stash push/pop unstages files? Shouldn't it preserve the directory\n> as-is?\n\nIt does, *provided* you invoke the pop step with `--index`.\n\nWhen `git stash push` makes a stash, it saves both the index\n(staging area) and working tree, as two separate commits.\n\nLater, at the time you apply the saved stash, you choose\nwhether to use the saved index / staging-area (`--index`) or to\ndiscard it (no `--index`).  The apply step uses the saved working\ntree in all cases, and if you also stashed untracked files with\n`-u` or `-a`, it uses this third commit as well.\n\nThe `pop` command is just `apply` followed by `drop` if the\napplication succeeds.\n\nChris\n"},{"id":"434733","messageId":"5f09cba9-b7dc-d7b6-1d3f-e7fb8ca28c6c@rawbw.com","threadId":"56445","inReplyTo":"CAPx1Gvc6noTDYPt9x3b4_TE0z8-KE5cB6KQHcn5UL9pi0cKoGg@mail.gmail.com","subject":"Re: stash push/pop unstages files?","fromName":"Yuri","fromEmail":"yuri@rawbw.com","sentAt":"2021-09-05T19:02:21Z","receivedAt":"2021-09-05T19:02:25Z","isPatch":false,"sender":{"key":"yuri@rawbw.com","avatar":null},"body":"On 9/5/21 10:15 AM, Chris Torek wrote:\n> It does,*provided*  you invoke the pop step with `--index`.\n>\n> When `git stash push` makes a stash, it saves both the index\n> (staging area) and working tree, as two separate commits.\n\n\nWhy 'stash push' and 'stash pop' are asymmetric in what they do by default?\nWouldn't it make more sense to make 'stash pop' precisely revert what \n'stash push' does, and have an option '--no-index' instead?\n\n\nYuri\n\n\n"},{"id":"434736","messageId":"CAPx1GvfEW4rVHjxmmNmAEOVYFgeehbmDQouCWWZx=aiiDy89Vg@mail.gmail.com","threadId":"56445","inReplyTo":"5f09cba9-b7dc-d7b6-1d3f-e7fb8ca28c6c@rawbw.com","subject":"Re: stash push/pop unstages files?","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2021-09-05T19:19:21Z","receivedAt":"2021-09-05T19:19:37Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Sun, Sep 5, 2021 at 12:02 PM Yuri <yuri@rawbw.com> wrote:\n> Why 'stash push' and 'stash pop' are asymmetric in what they do by default?\n> Wouldn't it make more sense to make 'stash pop' precisely revert what\n> 'stash push' does, and have an option '--no-index' instead?\n\nIf you ask me, yes, it would—but it would make even *more* sense\nif `git stash` didn't bother saving the index at all without `--index`, and\njust errored out if the index and working tree didn't match.  But I didn't\nwrite `git stash`.\n\nMy personal recommendation is: never (or hardly ever) use it.  Just\nmake a commit.\n\nChris\n"}]}