{"thread":{"id":"42024","subject":"Data loss when using \"git stash -u\" and ignored content in directories","startedAt":"2016-04-14T09:16:57Z","lastAt":"2016-04-14T09:16:57Z","messageCount":1,"participants":["Ulrich Buchgraber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"283440","messageId":"CAGxq=N-n5Vt-L4iaU2AyqYbH7oA-XcERx+oUWuSOj+rD2=MhLA@mail.gmail.com","threadId":"42024","inReplyTo":null,"subject":"Data loss when using \"git stash -u\" and ignored content in directories","fromName":"Ulrich Buchgraber","fromEmail":"ulrich.b@gmx.at","sentAt":"2016-04-14T09:16:57Z","receivedAt":"2016-04-14T09:16:57Z","isPatch":false,"sender":{"key":"ulrich.b@gmx.at","avatar":"https://gravatar.com/avatar/130d7c127b4a0aa8225806aebd0d6ed455666550790c1c9253a1674f8f0dd8ca?d=mp&s=160"},"body":"Hello,\n\nA \"git stash -u\" cleans all untracked files (after storing them), and\nnormally does not clean ignored files.\n\nBut: It cleans ignored files _within_ a directory, when the directory\nitself is not ignored, but its content (e.g. a \"dir/*\" ignore filter).\n\nThe bug seems to be that in the cleanup phase of \"git stash -u\" Git\nimmediately deletes untracked directories without checking if there\nare ignored files in there.\n\nSee the following reproduction sample. The last \"ls\" command shows\nthat the file \"ignored_dir_with_star/ignored.txt\" is lost.\n\n    git init\n\n    mkdir ignored_dir && touch ignored_dir/ignored.txt\n    mkdir ignored_dir_with_star && touch ignored_dir_with_star/ignored.txt\n\n    echo \"/ignored_dir\" >> .gitignore\n    echo \"/ignored_dir_with_star/*\" >> .gitignore\n    git add .gitignore\n    git commit -m \"added ignores\"\n\n    touch untracked.txt\n\n    ls -R\n    # => Output:\n    # .:\n    # ignored_dir/  ignored_dir_with_star/  untracked.txt\n    #\n    # ./ignored_dir:\n    # ignored.txt\n    #\n    # ./ignored_dir_with_star:\n    # ignored.txt\n\n    git stash -u\n    git stash pop\n\n    ls -R\n    # => Output:\n    # .:\n    # ignored_dir/  untracked.txt\n    #\n    # ./ignored_dir:\n    # ignored.txt\n\nNote that there is no data loss when instead using \"git stash\" or \"git\nstash -a\".\n\n(Tested with Git 2.8.1 on Ubuntu and Git for Windows version 2.8.1.windows.1.)\n\nUlrich\n"}]}