I'm sure we've all run into this problem: Want to cleanup a directory since it has a lot of old files we are no longer using. But when we want to commit our changes using git we see something like this:
I can think of very few other things than manually doing "git rm blahh blahh blahh" x many times which would annoy me more. Maybe TMNT on the NES ... ;)
So, I figured that "git add . " adds all the modified/new/renamed files, so why not try "git rm .". Well that didn't work, but there was a temping thought in my mind to try "git rm . -r". This recursively deletes files, and I thought it would only do the ones in question. Alas, it went about deleting everything... recursively ... duhh.
Fortunately, I've become git obsessed so with a "git reset --hard" I went back to the previous commit and all is ok.
After some sleuthing, it turns out there is a one trick pony to be able to do what I want,
git rm $(git ls-files --deleted)
With a git commit we're good to go!
Now, looking at the way I removed the files it appears to narrowly select the deleted files, I wonder if this will work on other types too (modified, new, etc)?
I'll try to remember to try when I come across this next.
I can think of very few other things than manually doing "git rm blahh blahh blahh" x many times which would annoy me more. Maybe TMNT on the NES ... ;)
So, I figured that "git add . " adds all the modified/new/renamed files, so why not try "git rm .". Well that didn't work, but there was a temping thought in my mind to try "git rm . -r". This recursively deletes files, and I thought it would only do the ones in question. Alas, it went about deleting everything... recursively ... duhh.
Fortunately, I've become git obsessed so with a "git reset --hard" I went back to the previous commit and all is ok.
After some sleuthing, it turns out there is a one trick pony to be able to do what I want,
git rm $(git ls-files --deleted)
With a git commit we're good to go!
Now, looking at the way I removed the files it appears to narrowly select the deleted files, I wonder if this will work on other types too (modified, new, etc)?
I'll try to remember to try when I come across this next.
No comments:
Post a Comment