Someone by accident just commited all of their bin and obj folders to our repo
(there are around 40 such folders). I would like to do a git rm -r
on all of these folders. Is there a command to do this?
Asked
Active
Viewed 1.1k times
3 Answers
26
Have backups,
find . -type d -name bin -exec git rm -r {} \;
find . -type d -name obj -exec git rm -r {} \;
Update
With bash, you can set the shopt globstar, and be happy:
shopt -s globstar
git rm -r **/{obj,bin}/
Finally, if you need to remove these from the history of the repository, look at git filter-branch
and read the section on 'Removing Objects' from the Pro Git Book

sehe
- 374,641
- 47
- 450
- 633
-
1Added reference to filter-branch and the pro git book, bash globstar option – sehe May 03 '11 at 14:16
-
1+1 for showing the 2-asterisk *globstar* which was new to me! – Daniel Böhmer May 03 '11 at 14:19
-
-1 for not using git clean. It was meant for these situations. – Adam Dymitruk May 03 '11 at 14:22
-
Interactive rebase is better than filter branch in this situation. – Adam Dymitruk May 03 '11 at 14:26
-
Thanks, sehe!! That did the trick. Now I need to revoke someone's repository privileges :) – Jacko May 03 '11 at 14:28
-
@adymitruk: Interactive rebase could work here, IFF there was a single commit that ONLY introduced the binaries. If not, you'd have to go back in history to amend the commit and then rebase the rest of the original branch on top of that again .... hassle. – sehe May 03 '11 at 14:33
-
1Not true. If it included other files that contain proper changes, mark the commit for edit. Unstage the obj/bin folder files and rebase --continue. Problem solved. I can't believe this answer got the tic. Such a fail for not using Git and resorting to "find". – Adam Dymitruk May 03 '11 at 15:51
-
No need to be so aggressive, IMHO. Good thing you point out that edit refers to contents, not the commit message (as I've been falsely understanding that). Well, then, I agree rebase is a (slightly) better fit here. Thanks again – sehe May 03 '11 at 16:05
-
On `OSX 10.10.2`, I get `find: illegal option -- t`. That's because you need to specify the starting directory immediately after `find`, so it's: `find . -type d -name bin -exec git rm -r {} \;` – 7stud Dec 29 '15 at 13:29
-
@7stud that works on all platforms with less GNU-y extended find. Adding that. – sehe Dec 29 '15 at 13:30
-
1Wow! After 4 years, you can still snap respond to questions! – 7stud Dec 29 '15 at 13:32
5
Once you revert (will keep files in history) or reset the commit,
git reset --hard
Once these are ignored files,
git clean -xdf
I use that to clean up before rebuilding a solution. Seems vs uses some dlls even after a checkout of a different branch or a merge.
You shouldn't need to resort to filter branch. Interactive rebase will do. Remember the --preserve-merges flag.
Hope this helps.

Adam Dymitruk
- 124,556
- 26
- 146
- 141
-
1
-
So is a bloated history. This assumes the user knows what they are doing, of course. – Adam Dymitruk May 03 '11 at 14:20
-
-
Leaving large files such as dlls and exes in the history by using revert instead of reset. – Adam Dymitruk May 03 '11 at 14:25
-
-
You asked what would lead to a bloated history. Git revert would do that which was mentioned in this answer and comments. – Adam Dymitruk May 03 '11 at 23:45