{"thread":{"id":"27262","subject":"ignored file can be deleted silently","startedAt":"2011-05-05T08:40:08Z","lastAt":"2011-05-05T19:51:58Z","messageCount":4,"participants":["Daniele Segato","Nguyen Thai Ngoc Duy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"167094","messageId":"BANLkTinEupQKfBofhH-qKD6gLGWyWRbGvw@mail.gmail.com","threadId":"27262","inReplyTo":null,"subject":"ignored file can be deleted silently","fromName":"Daniele Segato","fromEmail":"daniele.bilug@gmail.com","sentAt":"2011-05-05T08:40:08Z","receivedAt":"2011-05-05T08:40:08Z","isPatch":false,"sender":{"key":"daniele.bilug@gmail.com","avatar":null},"body":"Hi,\n\nI noticed that when i put a file in the git ignore If i switch to a\nbranch where the file is present and versioned git delete my local\nignored file replacing it with the content of the branch I switched\nthis is done silently and the file is gone forever if I don't have a\ncopy somewhere\n\nthis is a stupid testcase:\n\n$ git init\n$ echo 'content I dont care about' > testcase.txt\n$ git add testcase.txt\n$ git commit -m \"content I don't care about\"\n$ git checkout -b test\n$ echo 'testcase.txt' > .gitignore\n$ git rm testcase.txt\n$ echo 'content I do care a lot' > testcase.txt\n$ git add .gitignore\n$ git commit -m \"ignored testcase.txt\"\n$ cat testcase.txt\ncontent I do care a lot\n$ git checkout master\n$ cat testcase.txt\n$ git checkout test\n$ ls testcase.txt\nls: testcase.txt: No such file or directory\n\n\nThis may sound stupid (put a content you care about in an ignored\nfile) but think about environment configuration files\n\nit is common to initially commit them (wrong) then copy them to a\ntemplate file adding the original to ignore\nespecially if you are migrating from subversion where it is really\ncommon practice to have local modified file you never commit (and I\nthink git really miss a *feature* like this)\nthey can be very big and with a lot of environment options...\n\nif for some reason I had to switch to an old commit where the file is\nstill not ignored to do some test and I forgot that commit do not\nignore my little environment file I can lose it...\n\nI think git should warn me in some way and, at least, give me a backup\nof the file\n\nwhat do you think about it?\n\nregards,\nDaniele Segato\n"},{"id":"167108","messageId":"BANLkTi=C4pO83mT3pO0B_AMaK3RMOC4V8g@mail.gmail.com","threadId":"27262","inReplyTo":"BANLkTinEupQKfBofhH-qKD6gLGWyWRbGvw@mail.gmail.com","subject":"Re: ignored file can be deleted silently","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-05-05T14:18:15Z","receivedAt":"2011-05-05T14:18:15Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, May 5, 2011 at 3:40 PM, Daniele Segato <daniele.bilug@gmail.com> wrote:\n> I noticed that when i put a file in the git ignore If i switch to a\n> branch where the file is present and versioned git delete my local\n> ignored file replacing it with the content of the branch I switched\n> this is done silently and the file is gone forever if I don't have a\n> copy somewhere\n\nThis is on purpose. Commit f8a9d42 (read-tree: further loosen \"working\nfile will be lost\" check. - 2006-12-04) allowed ignored files to be\noverwritten. Perhaps we can have a config to tighten the check again?\n-- \nDuy\n"},{"id":"167122","messageId":"7viptp9jos.fsf@alter.siamese.dyndns.org","threadId":"27262","inReplyTo":"BANLkTi=C4pO83mT3pO0B_AMaK3RMOC4V8g@mail.gmail.com","subject":"Re: ignored file can be deleted silently","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-05-05T16:49:23Z","receivedAt":"2011-05-05T16:49:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> This is on purpose. Commit f8a9d42 (read-tree: further loosen \"working\n> file will be lost\" check. - 2006-12-04) allowed ignored files to be\n> overwritten. Perhaps we can have a config to tighten the check again?\n\nNo.  The real issue is that we have only two classes of paths.  Either\nignored or unignored.\n\nIf we see an unignored path not yet tracked, we notice and suggest \"that\nfile might be something valuable and you may forgot to add\" in \"status\"\noutput.  In that sense, \"unignored\" is a synonym of \"worth keeping\".\n\nMost of the time, \"ignored\" is also the same as \"can be safely discarded\"\n(think: *.o files that can be recreated).  If you do not allow them to be\ndiscarded, switching from a branch that has \"builtin/hello.c\" and leaves\nan ignored compilation artifact \"builtin/hello.o\" to another branch that\ndid not have \"builtin/\" directory (probably it is \"builtin-hello.c\" on\nthat branch), or even worse, a plain text file \"builtin\", would stop and\nget you into a horrible habit of constantly saying \"checkout -f\".  Even\nthough there may be cases where there are some files that are not tracked,\nthat you may not want to add, but you may still want to keep, because we\nhave only two ignored/unignored classes, that is how we have done things.\n\nIf you really want to fix this to everybody's satisfaction, you need to\nintroduce the third class, ignored-but-precious (IIRC, tla had such a\nconcept), and treat them as \"not worth nagging about potentially forgotten\nas an add target\" but still \"not automatically nukeable\".\n"},{"id":"167171","messageId":"1304625118.18121.9.camel@mastrogen","threadId":"27262","inReplyTo":"7viptp9jos.fsf@alter.siamese.dyndns.org","subject":"Re: ignored file can be deleted silently","fromName":"Daniele Segato","fromEmail":"daniele.bilug@gmail.com","sentAt":"2011-05-05T19:51:58Z","receivedAt":"2011-05-05T19:51:58Z","isPatch":false,"sender":{"key":"daniele.bilug@gmail.com","avatar":null},"body":"Il giorno gio, 05/05/2011 alle 09.49 -0700, Junio C Hamano ha scritto:\n> No.  The real issue is that we have only two classes of paths.  Either\n> ignored or unignored.\n\nI totally agree agree with you\na third class would be perfect for the job..\n\neven a *new* sintax in the ignore list could do\n"}]}