# Cleaning ignored files

2 messages from 2016-11-09 to 2016-11-10. Participants: Roman Terekhov, John Szakmeister.
Thread: https://gitlist.dev/t/44448

## Roman Terekhov, 2016-11-09 18:23

Subject: Cleaning ignored files
Message-ID: <CALbGNxUahc0b151niqS3Qd6N8wapY5RWJs1w0ZSf6ZW1=id6vA@mail.gmail.com>
URL: https://gitlist.dev/e/CALbGNxUahc0b151niqS3Qd6N8wapY5RWJs1w0ZSf6ZW1%3Did6vA%40mail.gmail.com

```
Hi,

I want to ask about git clean -dXf command behaviour.

I do the following:

$ mkdir gitignore_test
$ cd gitignore_test/
$ git init
Initialized empty Git repository in ~/gitignore_test/.git/

$ echo *.sln > .gitignore
$ git add .gitignore
$ git commit -m "add gitignore"
[master (root-commit) ef78a3c] add gitignore
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore

$ mkdir src
$ touch test.sln
$ touch src/test.sln
$ tree
.
├── src
│   └── test.sln
└── test.sln

1 directory, 2 files

$ git clean -dXf
Removing test.sln

$ tree
.
└── src
    └── test.sln

1 directory, 1 file


Why git clean -dXf does not remove all my test.sln files, but just one of them?

Roman Terekhov

```

## John Szakmeister, 2016-11-10 09:19

Subject: Re: Cleaning ignored files
Message-ID: <CAEBDL5VWpnoQdD6TJgdLBgFbb9HZzwYyLDbVz1O3s5As5otLQg@mail.gmail.com>
URL: https://gitlist.dev/e/CAEBDL5VWpnoQdD6TJgdLBgFbb9HZzwYyLDbVz1O3s5As5otLQg%40mail.gmail.com
In-Reply-To: <CALbGNxUahc0b151niqS3Qd6N8wapY5RWJs1w0ZSf6ZW1=id6vA@mail.gmail.com>

```
On Wed, Nov 9, 2016 at 1:23 PM, Roman Terekhov <roman.terekhov@gmail.com> wrote:
> Hi,
>
> I want to ask about git clean -dXf command behaviour.
>
> I do the following:
>
> $ mkdir gitignore_test
> $ cd gitignore_test/
> $ git init
> Initialized empty Git repository in ~/gitignore_test/.git/
>
> $ echo *.sln > .gitignore
> $ git add .gitignore
> $ git commit -m "add gitignore"
> [master (root-commit) ef78a3c] add gitignore
>  1 file changed, 1 insertion(+)
>  create mode 100644 .gitignore
>
> $ mkdir src
> $ touch test.sln
> $ touch src/test.sln
> $ tree
> .
> ├── src
> │   └── test.sln
> └── test.sln
>
> 1 directory, 2 files
>
> $ git clean -dXf
> Removing test.sln
>
> $ tree
> .
> └── src
>     └── test.sln
>
> 1 directory, 1 file
>
>
> Why git clean -dXf does not remove all my test.sln files, but just one of them?

src/ is not under version control, and currently git does not descend
into unknown folders to remove ignored files.  If you had a tracked or
staged file in src/, then git would descend into src/ and remove
test.sln as expected.  In your example, try doing:

$ touch src/foo.c
$ git add src/foo.c
$ git clean -dXf
Removing src/test.sln
Removing test.sln

Hope that helps!

-John

```
