{"thread":{"id":"38504","subject":"Bug report: Folder and files are deleted by git stash -u","startedAt":"2015-02-05T09:56:03Z","lastAt":"2015-02-05T19:37:31Z","messageCount":3,"participants":["Tobias Preuss","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"255622","messageId":"CADEaiE8zSptYy9GTi4ZZ2bZptbretW6kDM4srmrSqaYeavfFhg@mail.gmail.com","threadId":"38504","inReplyTo":null,"subject":"Bug report: Folder and files are deleted by git stash -u","fromName":"Tobias Preuss","fromEmail":"tobias.preuss@googlemail.com","sentAt":"2015-02-05T09:56:03Z","receivedAt":"2015-02-05T09:56:03Z","isPatch":false,"sender":{"key":"tobias.preuss@googlemail.com","avatar":"https://gravatar.com/avatar/aa7f7cede53018ff874dfb61fa4de920fff33234f1dd0570a9bed1630c3dce60?d=mp&s=160"},"body":"Hello.\n\nI noticed some bizarre behaviour when using: git stash -u.\nIt deletes folders which contain files configured to be ignored. I\nactually lost files by this which I could not restore.\n\nHere is how you can reproduce the case.\n\n1. Create a project folder to act as the root of the repository. `cd`\ninto the directory\n2. Create a folder `tracked-folder` with a file `tracked-file` in it.\nAdd some content to the file.\n3. Create a folder `untracked-folder` with a file `untracked-file` in\nit. Add some content to the file.\n4. Create a file `to-be-stashed`, add some content to the file.\n5. Create a `.gitignore` file with the following content: `untracked-file`.\n6. Initialize the Git repository: `git init .`\n7. Add all files to be tracked: `git add . & git commit`\n8. List the current content of the repository: `tree`. It should show\nthe following:\n\n├── to-be-stashed\n├── tracked-folder\n│   └── tracked-file\n└── untracked-folder\n    └── untracked-file\n\n9. Run `git stash -u` and inspect the folder again:\n\n.\n└── tracked-folder\n    └── tracked-file\n\n10. Run `git stash pop` and inspect the folder once again:\n\n.\n├── to-be-stashed\n└── tracked-folder\n    └── tracked-file\n\nThere you are - you just lost the whole folder.\n\nCan you please confirm or deny if this is a bug? Thank you.\nBest regards, Tobias\n"},{"id":"255638","messageId":"xmqqvbjgkw4i.fsf@gitster.dls.corp.google.com","threadId":"38504","inReplyTo":"CADEaiE8zSptYy9GTi4ZZ2bZptbretW6kDM4srmrSqaYeavfFhg@mail.gmail.com","subject":"Re: Bug report: Folder and files are deleted by git stash -u","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-05T19:15:41Z","receivedAt":"2015-02-05T19:15:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tobias Preuss <tobias.preuss@googlemail.com> writes:\n\n> I noticed some bizarre behaviour when using: git stash -u.\n> It deletes folders which contain files configured to be ignored.\n\nThe files you mark as ignored are expendable and this is not limited\nto \"stash\".\n\n    $ git init\n    Initialized empty Git repository in /var/tmp/x/ignore/.git/\n    $ echo \\*.o >.gitignore\n    $ git add .gitignore\n    $ git commit -m void\n    [master (root-commit) 457b70e] void\n     1 file changed, 1 insertion(+)\n     create mode 100644 .gitignore\n    $ echo a regular file >a\n    $ git add a\n    $ git commit -m \"a regular file\"\n    [master df839f0] a regular file\n     1 file changed, 1 insertion(+)\n     create mode 100644 a\n\nWe have two regular files, .gitignore and a, on 'master' branch.\n\n    $ git checkout -b side HEAD^\n    Switched to a new branch 'side'\n    $ mkdir a\n    $ >a/file.c\n    $ >a/file.o\n    $ git add .\n    $ git commit -m 'a/file.c'\n    [side 3199d63] a/file.c\n     1 file changed, 0 insertions(+), 0 deletions(-)\n     create mode 100644 a/file.c\n\nWe have two regular files, .gitignore and a/file.c, on 'side' branch,\nwhich is checked out.  The object files that would be created by\ncompiling source files are set to be ignored by .gitignore rule.\n\nHere is what should happen when you go to 'master':\n\n    $ git checkout master\n    Switched to branch 'master'\n    $ /bin/ls -AF\n    a  .git/  .gitignore\n\nThat is, a/file.c that is safely stored in 'side' branch is removed,\na/file.o that is expendable is deleted, and the empty directory 'a'\nnow can be replaced with the regular file 'a' the 'master' branch\nwants to have.\n"},{"id":"255645","messageId":"xmqqegq4kv44.fsf@gitster.dls.corp.google.com","threadId":"38504","inReplyTo":"xmqqvbjgkw4i.fsf@gitster.dls.corp.google.com","subject":"Re: Bug report: Folder and files are deleted by git stash -u","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-05T19:37:31Z","receivedAt":"2015-02-05T19:37:31Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Tobias Preuss <tobias.preuss@googlemail.com> writes:\n>\n>> I noticed some bizarre behaviour when using: git stash -u.\n>> It deletes folders which contain files configured to be ignored.\n>\n> The files you mark as ignored are expendable and this is not limited\n> to \"stash\".\n> ...\n> Here is what should happen when you go to 'master':\n>\n>     $ git checkout master\n>     Switched to branch 'master'\n>     $ /bin/ls -AF\n>     a  .git/  .gitignore\n>\n> That is, a/file.c that is safely stored in 'side' branch is removed,\n> a/file.o that is expendable is deleted, and the empty directory 'a'\n> now can be replaced with the regular file 'a' the 'master' branch\n> wants to have.\n\nAddendum 1.\n\n    If *.o files are not treated expendable, you would be forced to\n    \"make clean\" every time you switch between these two branches,\n    which is unacceptable.\n\nAddendum 2.\n\n    There was an old wishlist item to introduce another class of\n    paths (in addition to the \"tracked\", \"untracked\" and \"ignored\")\n    that are \"ignored-but-precious\".  Then \"*.o\" would still be\n    expendable while a directory that must become a regular file\n    with \"ignored-but-precious\" files in it would prevent switching\n    from branch 'side' to 'master' in the illustration in the\n    previous message in order to keep that \"ignored-but-precious\"\n    file.\n\n    But nobody needed such a feature badly enough to step up and\n    implement it.\n\n    cf. http://article.gmane.org/gmane.comp.version-control.git/185746\n"}]}