tags:

views:

342

answers:

2

I removed 777 files which were in Git's branch newFeature by

rm !(example)

I would like to commit. Git ask me to manually remove each of the removed files by

git rm file

It would take a lot of time to write the above command for all 777 files which names are not similar.

How can I remove these 777 files in my Git branch newFeature? I want to keep them as a backup for later use, but now, I want to be without them.

+1  A: 

Do you have a list of these files somewhere, or can you get them using git? If so, and if you're on a Unix box, use that list and xargs together to give the filenames to git rm.

Jon Skeet
Downvoters - reasons are welcome...
Jon Skeet
Sorry for the delay Jon. I did the downvoting, as I struggled to understand what such a poorly documented, not very "git-related" answer was still able to attract 2 upvotes.
VonC
I very much admire the quality of your many (many) answers and this one strike me as... not in the same league than your usual wisdom ;)
VonC
1+: You made me able to search my Mac fast. For instance, "$locate Masi | xargs -0 grep bar" gives me a significant result, while "$locate Masi | grep bar" is useless for me. Thank you!
Masi
... and I stand corrected! :) @Masi, you should select Jon's answer if it works better for you (although I am not sure about the direct link with the original question)
VonC
Basically my answer is based on, "Well, I don't know enough git to do all of this in one go - but we know how to do it for one file. If we can get the list of files, xargs will do the rest" :) Of course it's very similar to your for/do/done loop.
Jon Skeet
@VonC: Your answer is the best answer for the question in hand. Jon's answer is outstanding generally. It gives me data which allows me to solve my other problems too.
Masi
+9  A: 
git add -u

It will "git delete" all files you removed.

From Git add:

u
--update

Update only files that git already knows about, staging modified content for commit and marking deleted files for removal.
This is similar to what "git commit -a" does in preparation for making a commit, except that the update is limited to paths specified on the command line.
If no paths are specified, all tracked files in the current directory and its subdirectories are updated.


The "plumbing way" was indeed some kind of script one-line

for i in ` git st | grep deleted | awk ‘{print $3}’ ` ; do git rm $i; done

or for Windows box with GnuWin32

git st | grep deleted | gawk "{print \"git rm \"$3}" | cmd

But git add -u is the main porcelain way to do it.

VonC