threads / discuss / 6507

git-rm'ing all dead files

Subject: git-rm'ing all dead files

## tl;dr

5 messages between Jan 24, 2007 and Jan 24, 2007.

replies: 4people: 2as markdown or json

Pazu· Jan 24, 2007, 16:17 UTC · lore

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· Jan 24, 2007, 16:25 UTC · re: Pazu · lore

Re: git-rm'ing all dead files

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· Jan 24, 2007, 16:51 UTC · re: Johannes Schindelin · lore

Re: git-rm'ing all dead files

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· Jan 24, 2007, 16:57 UTC · re: Pazu · lore

Re: git-rm'ing all dead files

Hi,
On Wed, 24 Jan 2007, Pazu wrote:
Show 14 quoted lines
> 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· Jan 24, 2007, 17:02 UTC · re: Johannes Schindelin · lore

Re: git-rm'ing all dead files

2007/1/24, Johannes Schindelin <Johannes.Schindelin@gmx.de>:
Show 6 quoted lines
> 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

← back to recent threads