{"thread":{"id":"40982","subject":"git stash save -u deletes ignored files without stashing them","startedAt":"2015-12-13T07:51:09Z","lastAt":"2016-02-04T07:40:11Z","messageCount":2,"participants":["Michael Brade","Kevin Locke"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"274339","messageId":"566D236D.5090904@kde.org","threadId":"40982","inReplyTo":null,"subject":"git stash save -u deletes ignored files without stashing them","fromName":"Michael Brade","fromEmail":"brade@kde.org","sentAt":"2015-12-13T07:51:09Z","receivedAt":"2015-12-13T07:51:09Z","isPatch":false,"sender":{"key":"brade@kde.org","avatar":null},"body":"Hi,\n\nand it does so if .gitignore has not been committed yet. This is with\ngit version 2.6.3. To reproduce:\n\nmkdir test\ncd test\ngit init\n\necho \"test\" > test\necho \"something.txt\" > .gitignore\n\ngit add test .gitignore\ngit commit -a -m \"init\"\n\nmkdir node_modules\necho \"something\" > node_modules/file.txt\necho \"node_modules\" >> .gitignore\n\ngit stash save -u\n\nNow node_modules will be deleted even though it was ignored at the time\nof the \"git stash save -u\". Apparently .gitignore is reverted first,\nthen the cleanup is done taking the new state of .gitignore into account\nwhere node_modules is now untracked and not ignored anymore, thus\ndeleting it.\n\nI think this should be considered a bug that can cause data loss, even\nif only in rare cases.\n\nthanks,\n  Michael\n\nPS: I'm not subscribed.\n"},{"id":"277370","messageId":"20160204074011.GA25382@kevinolos","threadId":"40982","inReplyTo":"566D236D.5090904@kde.org","subject":"Re: git stash save -u deletes ignored files without stashing them","fromName":"Kevin Locke","fromEmail":"kevin@kevinlocke.name","sentAt":"2016-02-04T07:40:11Z","receivedAt":"2016-02-04T07:40:11Z","isPatch":false,"sender":{"key":"kevin@kevinlocke.name","avatar":"https://avatars.githubusercontent.com/u/336433?v=4"},"body":"On Sun, 2015-12-13 at 7:51, Michael Brade wrote:\n> Now node_modules will be deleted even though it was ignored at the time\n> of the \"git stash save -u\". Apparently .gitignore is reverted first,\n> then the cleanup is done taking the new state of .gitignore into account\n> where node_modules is now untracked and not ignored anymore, thus\n> deleting it.\n\nAnother effect of this, although obviously less severe, is that it can\ncreate a stash which can not be applied without additional work:\n\ngit init\necho test.txt > .gitignore\ngit add .gitignore\ngit commit -m init\necho stuff > test.txt\necho > .gitignore\ngit stash -u\n\nAt this point the stash contains test.txt (untracked) and the changes\nto .gitignore which unignore the file, but test.txt is also left in\nthe working directory.  Attempting to apply the stash produces the\nfollowing result:\n\n$ git stash apply\ntest.txt already exists, no checkout\nCould not restore untracked files from stash\n\nSo the user must remove it themselves, which can be confusing since\nthe file is not listed in `git stash show`, which doesn't include\nuntracked files.\n\nKevin\n\nP.S.  Please CC me on replies.  Thanks!\n"}]}