Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: need to recursively 'git rm' the contents of all bin and obj folders

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?

like image 802
Jacko Avatar asked May 03 '11 14:05

Jacko


People also ask

Can I delete BIN and OBJ folders?

Delete bin and obj foldersThe bin and obj folders are usually safe to delete since they are automatically generated when the solution/project is being build by Visual Studio/MSBuild. This feature is off by default, but can easily be enabled in the settings.

Should I git ignore bin and obj folders?

gitignore should ignore everything called obj or bin at all lower levels.


2 Answers

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

like image 184
sehe Avatar answered Sep 29 '22 21:09

sehe


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.

like image 30
Adam Dymitruk Avatar answered Sep 29 '22 22:09

Adam Dymitruk