Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git wildcard - remove all instances of a subdirectory

I am trying to execute git rm --cached -r <folder> to remove all instances of a folder named .svn recursively. I have tried this:

.svn
/.svn
/*/.svn
/*/*/.svn

etc 

And it works, but I'm sure there is a more dynamic way.

Thanks

like image 796
AaronHS Avatar asked Mar 08 '12 11:03

AaronHS


People also ask

Does Gitignore work in subfolders?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

How do I remove all .git folders?

Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains.

What does rm .git do?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.


3 Answers

The right solution would be:

find . -type d -name '.svn' -print0 | xargs -0 git rm --cached -r --

@gregor's will fail on the directories with spaces.

like image 118
Anton Avatar answered Nov 25 '22 07:11

Anton


find, pipes and xargs are your friends:

find . -name .svn | xargs git rm -r 
like image 38
gregor Avatar answered Nov 25 '22 06:11

gregor


If you don't have any other changes in your worktree (you can stash them first), there's probably an easier way:

find -type d -name .svn -delete
git add -u
git commit -m 'remove svn folders -- no idea which maniac would stage them'

If you only want to unstage them, but not physically delete them, go with anton's answer:

find -type d -name .svn -print0 | xargs -0 git rm -r --cached
like image 27
knittl Avatar answered Nov 25 '22 06:11

knittl