Git rm several files?
I found git rm
's handling of wild cards annoying. Find can do the trick in one line:
find . -name '*.c' -exec git rm {} \;
the {}
is where the file name will be substituted. The great thing about find
is it can filter on a huge variety of file attributes not just name.
Just delete them using any other method (Explorer, whatever), then run git add -A
. As to reverting several files, you can also checkout a directory.
You can give wildcards to git rm
.
e.g.
git rm *.c
Or you can just write down the names of all the files in another file, say filesToRemove.txt
:
path/to/file.c
path/to/another/file2.c
path/to/some/other/file3.c
You can automate this:
find . -name '*.c' > filesToRemove.txt
Open the file and review the names (to make sure it's alright).
Then:
cat filesToRemove.txt | xargs git rm
Or:
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).