{"thread":{"id":"46144","subject":"git stash --include-untracked possible destructive behavior","startedAt":"2017-06-08T11:58:49Z","lastAt":"2017-06-09T08:28:06Z","messageCount":5,"participants":["Marc Strapetz","Joel Teichroeb","Brandon Williams"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"321750","messageId":"2b695c73-9de2-5502-6d19-ba4ad0114978@syntevo.com","threadId":"46144","inReplyTo":null,"subject":"git stash --include-untracked possible destructive behavior","fromName":"Marc Strapetz","fromEmail":"marc.strapetz@syntevo.com","sentAt":"2017-06-08T11:52:13Z","receivedAt":"2017-06-08T11:58:49Z","isPatch":false,"sender":{"key":"marc.strapetz@syntevo.com","avatar":"https://avatars.githubusercontent.com/u/3380730?v=4"},"body":"One of our users has just discovered a destructive behavior of git stash \n--include-untracked: ignored files within non-ignored directories will \nnot be stashed as untracked files (expected), but will still be removed \nfrom the working tree. The problem is reproducible by following command \nsequence:\n\n   $ git init\n   $ echo \"1\" > file.txt\n   $ mkdir Data\n   $ echo \"1\" > Data/ignored.txt\n   $ echo \"Data/*\" > .gitignore\n   $ git add .\n   $ git commit -m \"initial import\"\n   $ echo \"2\" > file.txt\n   $ git stash save --include-untracked\n   Saved working directory and index state WIP on master: 6ce5303 initial\n   import\n\n   $ git stash show stash@{1}\n    file.txt | 2 +-\n    1 file changed, 1 insertion(+), 1 deletion(-)\n\n   $ ls Data\n   ls: cannot access 'Data': No such file or directory\n\nAs you can see, after saving the stash, stash@{1} doesn't contain \nData/ignored.txt, but the entire Data directory is still gone from the \nworking tree. As a consequence, applying the stash won't bring back \nData/ignored.txt, too.\n\n   $ git stash apply\n   On branch master\n   Changes not staged for commit:\n     (use \"git add <file>...\" to update what will be committed)\n     (use \"git checkout -- <file>...\" to discard changes in working\n     directory)\n\n           modified:   file.txt\n\n   no changes added to commit (use \"git add\" and/or \"git commit -a\")\n\n   $ ls Data\n   ls: cannot access 'Data': No such file or directory\n\nNote that when changing .gitignore to \"Data/\" instead of \"Data/*\", \n--include-untracked works as expected.\n\nTested with: git version 2.13.0.windows.1\n\n-Marc\n"},{"id":"321774","messageId":"197975d0-7ec3-0ff4-9201-48226fd3b60c@teichroeb.net","threadId":"46144","inReplyTo":"2b695c73-9de2-5502-6d19-ba4ad0114978@syntevo.com","subject":"Re: git stash --include-untracked possible destructive behavior","fromName":"Joel Teichroeb","fromEmail":"joel@teichroeb.net","sentAt":"2017-06-08T22:13:47Z","receivedAt":"2017-06-08T22:13:53Z","isPatch":false,"sender":{"key":"joel@teichroeb.net","avatar":"https://avatars.githubusercontent.com/u/240865?v=4"},"body":"It looks like it's an issue with git clean, as that's what stash uses \ninternally. You can try your same test, but replace git stash with \"git \nclean -df\" and it will delete Data. Maybe clean should check if there \nare any ignored files in an untracked directory and only remove it if -x \nis specified?\n\nJoel\n"},{"id":"321775","messageId":"20170608222949.GA121539@google.com","threadId":"46144","inReplyTo":"197975d0-7ec3-0ff4-9201-48226fd3b60c@teichroeb.net","subject":"Re: git stash --include-untracked possible destructive behavior","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-06-08T22:29:49Z","receivedAt":"2017-06-08T22:29:58Z","isPatch":false,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 06/08, Joel Teichroeb wrote:\n> It looks like it's an issue with git clean, as that's what stash\n> uses internally. You can try your same test, but replace git stash\n> with \"git clean -df\" and it will delete Data. Maybe clean should\n> check if there are any ignored files in an untracked directory and\n> only remove it if -x is specified?\n> \n> Joel\n\nThere was someone working on fixing clean, you can look at the patch\nseries at\nhttps://public-inbox.org/git/20170523100937.8752-1-sxlijin@gmail.com/\nthough I'm unsure of the series' status.\n\n-- \nBrandon Williams\n"},{"id":"321777","messageId":"e45eed21-f808-b2a8-a01b-78c18a9c343a@teichroeb.net","threadId":"46144","inReplyTo":"20170608222949.GA121539@google.com","subject":"Re: Re: git stash --include-untracked possible destructive behavior","fromName":"Joel Teichroeb","fromEmail":"joel@teichroeb.net","sentAt":"2017-06-08T22:39:10Z","receivedAt":"2017-06-08T22:39:28Z","isPatch":false,"sender":{"key":"joel@teichroeb.net","avatar":"https://avatars.githubusercontent.com/u/240865?v=4"},"body":"Looks like that series was merged last week, fixing this issue.\n\nMarc, the fix will probably be in git 2.14.\n\nJoel\n"},{"id":"321816","messageId":"7bb9829b-21a4-bd9e-c6f1-521b808793ea@syntevo.com","threadId":"46144","inReplyTo":"e45eed21-f808-b2a8-a01b-78c18a9c343a@teichroeb.net","subject":"Re: git stash --include-untracked possible destructive behavior","fromName":"Marc Strapetz","fromEmail":"marc.strapetz@syntevo.com","sentAt":"2017-06-09T08:28:21Z","receivedAt":"2017-06-09T08:28:06Z","isPatch":false,"sender":{"key":"marc.strapetz@syntevo.com","avatar":"https://avatars.githubusercontent.com/u/3380730?v=4"},"body":"On 09.06.2017 00:39, Joel Teichroeb wrote:\n> Looks like that series was merged last week, fixing this issue.\n> \n> Marc, the fix will probably be in git 2.14.\n\nThanks, I can confirm that with current master \"git clean\" as well as \n\"git stash\" are working properly now (tested on Linux). I'm looking \nforward to version 2.14.\n\n-Marc\n"}]}