# ignored file can be deleted silently

4 messages from 2011-05-05 to 2011-05-05. Participants: Daniele Segato, Nguyen Thai Ngoc Duy, Junio C Hamano.
Thread: https://gitlist.dev/t/27262

## Daniele Segato, 2011-05-05 08:40

Subject: ignored file can be deleted silently
Message-ID: <BANLkTinEupQKfBofhH-qKD6gLGWyWRbGvw@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTinEupQKfBofhH-qKD6gLGWyWRbGvw%40mail.gmail.com

```
Hi,

I noticed that when i put a file in the git ignore If i switch to a
branch where the file is present and versioned git delete my local
ignored file replacing it with the content of the branch I switched
this is done silently and the file is gone forever if I don't have a
copy somewhere

this is a stupid testcase:

$ git init
$ echo 'content I dont care about' > testcase.txt
$ git add testcase.txt
$ git commit -m "content I don't care about"
$ git checkout -b test
$ echo 'testcase.txt' > .gitignore
$ git rm testcase.txt
$ echo 'content I do care a lot' > testcase.txt
$ git add .gitignore
$ git commit -m "ignored testcase.txt"
$ cat testcase.txt
content I do care a lot
$ git checkout master
$ cat testcase.txt
$ git checkout test
$ ls testcase.txt
ls: testcase.txt: No such file or directory


This may sound stupid (put a content you care about in an ignored
file) but think about environment configuration files

it is common to initially commit them (wrong) then copy them to a
template file adding the original to ignore
especially if you are migrating from subversion where it is really
common practice to have local modified file you never commit (and I
think git really miss a *feature* like this)
they can be very big and with a lot of environment options...

if for some reason I had to switch to an old commit where the file is
still not ignored to do some test and I forgot that commit do not
ignore my little environment file I can lose it...

I think git should warn me in some way and, at least, give me a backup
of the file

what do you think about it?

regards,
Daniele Segato

```

## Nguyen Thai Ngoc Duy, 2011-05-05 14:18

Subject: Re: ignored file can be deleted silently
Message-ID: <BANLkTi=C4pO83mT3pO0B_AMaK3RMOC4V8g@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3DC4pO83mT3pO0B_AMaK3RMOC4V8g%40mail.gmail.com
In-Reply-To: <BANLkTinEupQKfBofhH-qKD6gLGWyWRbGvw@mail.gmail.com>

```
On Thu, May 5, 2011 at 3:40 PM, Daniele Segato <daniele.bilug@gmail.com> wrote:
> I noticed that when i put a file in the git ignore If i switch to a
> branch where the file is present and versioned git delete my local
> ignored file replacing it with the content of the branch I switched
> this is done silently and the file is gone forever if I don't have a
> copy somewhere

This is on purpose. Commit f8a9d42 (read-tree: further loosen "working
file will be lost" check. - 2006-12-04) allowed ignored files to be
overwritten. Perhaps we can have a config to tighten the check again?
-- 
Duy

```

## Junio C Hamano, 2011-05-05 16:49

Subject: Re: ignored file can be deleted silently
Message-ID: <7viptp9jos.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7viptp9jos.fsf%40alter.siamese.dyndns.org
In-Reply-To: <BANLkTi=C4pO83mT3pO0B_AMaK3RMOC4V8g@mail.gmail.com>

```
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:

> This is on purpose. Commit f8a9d42 (read-tree: further loosen "working
> file will be lost" check. - 2006-12-04) allowed ignored files to be
> overwritten. Perhaps we can have a config to tighten the check again?

No.  The real issue is that we have only two classes of paths.  Either
ignored or unignored.

If we see an unignored path not yet tracked, we notice and suggest "that
file might be something valuable and you may forgot to add" in "status"
output.  In that sense, "unignored" is a synonym of "worth keeping".

Most of the time, "ignored" is also the same as "can be safely discarded"
(think: *.o files that can be recreated).  If you do not allow them to be
discarded, switching from a branch that has "builtin/hello.c" and leaves
an ignored compilation artifact "builtin/hello.o" to another branch that
did not have "builtin/" directory (probably it is "builtin-hello.c" on
that branch), or even worse, a plain text file "builtin", would stop and
get you into a horrible habit of constantly saying "checkout -f".  Even
though there may be cases where there are some files that are not tracked,
that you may not want to add, but you may still want to keep, because we
have only two ignored/unignored classes, that is how we have done things.

If you really want to fix this to everybody's satisfaction, you need to
introduce the third class, ignored-but-precious (IIRC, tla had such a
concept), and treat them as "not worth nagging about potentially forgotten
as an add target" but still "not automatically nukeable".

```

## Daniele Segato, 2011-05-05 19:51

Subject: Re: ignored file can be deleted silently
Message-ID: <1304625118.18121.9.camel@mastrogen>
URL: https://gitlist.dev/e/1304625118.18121.9.camel%40mastrogen
In-Reply-To: <7viptp9jos.fsf@alter.siamese.dyndns.org>

```
Il giorno gio, 05/05/2011 alle 09.49 -0700, Junio C Hamano ha scritto:
> No.  The real issue is that we have only two classes of paths.  Either
> ignored or unignored.

I totally agree agree with you
a third class would be perfect for the job..

even a *new* sintax in the ignore list could do

```
