Tower Tower - 1 year ago 86
Git Question

Git rm several files?

How do I easily remove several files without manually typing the full paths of all of them to

git rm
? I have plenty of modified files I'd like to keep so removing all modified is not possible either.

And also it is possible to revert the changes of several files without manually typing
git checkout -- /path/to/file

Answer Source

You can give wildcards to git rm.


git rm *.c

Or you can just write down the names of all the files in another file, say filesToRemove.txt:


You can automate this:

find . -name '*.c' > filesToRemove.txt

Open the file and review the names (to make sure it's alright).


cat filesToRemove.txt | xargs git rm


for i in `cat filesToRemove.txt`; do git rm $i; done

Check the manpage for xargs for more options (esp. if it's too many files).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download