# git-rm'ing all dead files

5 messages from 2007-01-24 to 2007-01-24. Participants: Pazu, Johannes Schindelin.
Thread: https://gitlist.dev/t/6507

## Pazu, 2007-01-24 16:17

Subject: git-rm'ing all dead files
Message-ID: <loom.20070124T171435-429@post.gmane.org>
URL: https://gitlist.dev/e/loom.20070124T171435-429%40post.gmane.org

```
I couldn't find an easy way to remove all "dead" files from the index, i.e.,
call git-rm on all files that are missing from the working copy.

Here's the scenario: I moved/added/removed a lot of files using a GUI tool; now
I need to reflect those changes in git. Using git-commit -a isn't the best
choice because there are local modifications I don't want to commit. I can use
"git add ." to automatically stage all new files, but how to the same for
removed files?

-- Pazu

```

## Johannes Schindelin, 2007-01-24 16:25

Subject: Re: git-rm'ing all dead files
Message-ID: <Pine.LNX.4.63.0701241723560.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0701241723560.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <loom.20070124T171435-429@post.gmane.org>

```
Hi,

On Wed, 24 Jan 2007, Pazu wrote:

> I couldn't find an easy way to remove all "dead" files from the index, 
> i.e., call git-rm on all files that are missing from the working copy.

How about

	git ls-files -z --deleted | git update-index -z --remove --stdin

?

Ciao,
Dscho

```

## Pazu, 2007-01-24 16:51

Subject: Re: git-rm'ing all dead files
Message-ID: <9e7ab7380701240851u1249b46ch36450fcf91bf7986@mail.gmail.com>
URL: https://gitlist.dev/e/9e7ab7380701240851u1249b46ch36450fcf91bf7986%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.63.0701241723560.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
2007/1/24, Johannes Schindelin <Johannes.Schindelin@gmx.de>:

> How about
>
>         git ls-files -z --deleted | git update-index -z --remove --stdin

Aha. I was trying

    git-ls-files -d | xargs git rm --cached

but most removed files contains spaces in their names, and that
screwed git-rm up. I've even noticed the -z option on git-ls-files,
but couldn't find one on git-rm, and I completely forgot about
git-update-index.

Thanks, Johannes. This should do the trick.

-- Pazu

```

## Johannes Schindelin, 2007-01-24 16:57

Subject: Re: git-rm'ing all dead files
Message-ID: <Pine.LNX.4.63.0701241756300.22628@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0701241756300.22628%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <9e7ab7380701240851u1249b46ch36450fcf91bf7986@mail.gmail.com>

```
Hi,

On Wed, 24 Jan 2007, Pazu wrote:

> 2007/1/24, Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> 
> > How about
> > 
> >         git ls-files -z --deleted | git update-index -z --remove --stdin
> 
> Aha. I was trying
> 
>    git-ls-files -d | xargs git rm --cached
> 
> but most removed files contains spaces in their names, and that
> screwed git-rm up. I've even noticed the -z option on git-ls-files,
> but couldn't find one on git-rm, and I completely forgot about
> git-update-index.

You _can_ use

	git ls-files -z -d | xargs -0 git rm --cached

So, you did not find that option with git-rm, because it is an option to 
xargs...

Ciao,
Dscho

```

## Pazu, 2007-01-24 17:02

Subject: Re: git-rm'ing all dead files
Message-ID: <9e7ab7380701240902i4168cc40x1629e76bdf75dcfb@mail.gmail.com>
URL: https://gitlist.dev/e/9e7ab7380701240902i4168cc40x1629e76bdf75dcfb%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.63.0701241756300.22628@wbgn013.biozentrum.uni-wuerzburg.de>

```
2007/1/24, Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> You _can_ use
>
>         git ls-files -z -d | xargs -0 git rm --cached
>
> So, you did not find that option with git-rm, because it is an option to
> xargs...

I remember trying that, but git-rm was still confused about spaces in
filenames. I'll try it again the next time I'm in a situation like
that.

-- Pazu

```
