Skip to contentSkip to conversation

git-rm'ing all dead files

DISCUSSION Pazu 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore

Pazu

author
#0 lore raw

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

#1 lore raw

Hi,

Quoted 2 lines · Pazu

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

author
#2 lore raw

2007/1/24, Johannes Schindelin <[email protected]>:

Quoted 3 lines

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

#3 lore raw

Hi,

Quoted 6 lines · Pazu

2007/1/24, Johannes Schindelin <[email protected]>:

Quoted 3 lines

How about

        git ls-files -z --deleted | git update-index -z --remove --stdin
Quoted 8 lines

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

author
#4 lore raw

2007/1/24, Johannes Schindelin <[email protected]>:

Quoted 6 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