{"thread":{"id":"37189","subject":".gitignore and git stash -u","startedAt":"2014-07-22T20:55:01Z","lastAt":"2014-07-22T21:22:29Z","messageCount":2,"participants":["Jeffry Johnston","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"246521","messageId":"CAH4Lw1p4UUAH5LcrVEcXtr75Jdfp8osYN2vUk=nkAttosOOjDw@mail.gmail.com","threadId":"37189","inReplyTo":null,"subject":".gitignore and git stash -u","fromName":"Jeffry Johnston","fromEmail":"jeff@kidsquid.com","sentAt":"2014-07-22T20:55:01Z","receivedAt":"2014-07-22T20:55:01Z","isPatch":false,"sender":{"key":"jeff@kidsquid.com","avatar":null},"body":"We had been experiencing \"random\" deletions of files and directories,\nand we finally figured out what they were: git stash -u.  A coworker\nhappened upon a webpage (after losing a weeks worth of experimental\nwork, back to his last backup), which described our problems exactly:\n\nhttp://blog.icefusion.co.uk/git-stash-can-delete-ignored-files-git-stash-u/\n\nThe command git stash -u deletes ignored files from the hard drive..\nvery dangerous! Which leads me to my first question: Why does git\nstash -u delete these files but a checkout doesn't? It seems\ninconsistent.\n\nWe have the following in .gitignore, which is directly related to the\nproblems we're having (please note, we're using git on Windows, in\ncase that makes a syntax difference):\n\n*/**/*\n![Ss][Rr][Cc]/**/*\n\nSo what that does is ignores every file and subdirectory at the top\nlevel, and then un-ignores Src/ and all files/dirs under that (we have\na few more that we unignore). The reason behind this is we have files\nthat are generated in the same tree as the source code, and\nunfortunately it is infeasible to change that design. So, if someone\ncreates Data and puts their own custom configuration file it in, it\ndoesn't contaminate the repository. However, if course they don't want\nto lose their configuration file either.\n\nMy understanding from the linked page is that our problem is having\nthe /* at the end which causes the files to be ignored and not the\ndirectories themselves. However, I couldn't seem to find a combination\nwithout the trailing /* that duplicated the functionality we had,  but\nthat prevented git stash from deleting our files. Can anyone provide\nme with one? This is what I am really after.\n\nI have come up with an inelegant workaround. If I add this line to .gitignore:\n\n!Data/.placeholder\n\nAnd then commit an empty .placeholder file, it seems to fix the\ndeletion problem. After that, we can place all sorts of untracked\nfiles and sub-directories and they don't get deleted during a stash. I\nguess it's because that tracked file keeps the directory \"alive\" in\nsome fashion, but I am not sure I understand why the sub-directories\nare not deleted though, can anyone enlighten me on that? I would have\nexpected to have to put a .placeholder file in every sub-directory\nunder Data to prevent them from getting deleted too (because of the **\nin the .gitignore line).\n\nAnother thing we were considering is modifying git itself to provide a\ncommand-line option not to delete ignored files during a stash. Can\nsomeone point me to the appropriate file?\n\nThanks a lot,\nJeff\n"},{"id":"246525","messageId":"xmqqd2cxf5re.fsf@gitster.dls.corp.google.com","threadId":"37189","inReplyTo":"CAH4Lw1p4UUAH5LcrVEcXtr75Jdfp8osYN2vUk=nkAttosOOjDw@mail.gmail.com","subject":"Re: .gitignore and git stash -u","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-07-22T21:22:29Z","receivedAt":"2014-07-22T21:22:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeffry Johnston <jeff@kidsquid.com> writes:\n\n> We had been experiencing \"random\" deletions of files and directories,\n> and we finally figured out what they were: git stash -u.  A coworker\n> happened upon a webpage (after losing a weeks worth of experimental\n> work, back to his last backup), which described our problems exactly:\n>\n> http://blog.icefusion.co.uk/git-stash-can-delete-ignored-files-git-stash-u/\n>\n> The command git stash -u deletes ignored files from the hard drive..\n> very dangerous!\n\nAlthough I never use \"stash --include-untracked\" myself, I think it\nis deliberate that the command removes all the untracked files.  The\nauthor of that \"feature\" explains its use this way:\n\ncommit 787513027a7d0af3c2cd2f04b85bc7136d580586\nAuthor: David Caldwell <david@porkrind.org>\nDate:   Fri Jun 24 17:56:06 2011 -0700\n\n    stash: Add --include-untracked option to stash and remove all untracked files\n    \n    The --include-untracked option acts like the normal \"git stash save\" but\n    also adds all untracked files in the working directory to the stash and then\n    calls \"git clean --force --quiet\" to restore the working directory to a\n    pristine state.\n    \n    This is useful for projects that need to run release scripts. With this\n    option, the release scripts can be from the main working directory so one\n    does not have to maintain a \"clean\" directory in parallel just for\n    releasing. Basically the work-flow becomes:\n    \n       $ git tag release-1.0\n       $ git stash --include-untracked\n       $ make release\n       $ git clean -f\n       $ git stash pop\n    \n    \"git stash\" alone is not enough in this case--it leaves untracked files\n    lying around that might mess up a release process that expects everything to\n    be very clean or might let a release succeed that should actually fail (due\n    to a new source file being created that hasn't been committed yet).\n    \n    Signed-off-by: David Caldwell <david@porkrind.org>\n    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n"}]}