First, make sure we remove .svn
folders and files from tracking by adding a new line ".svn/
" to our .gitignore
file.
Next, we will find all folders that are named .svn
and for each folder found remove all files contained within it. Note the only difference between the two commands below is that the first has an extra flag of -n
which allows us to perform a dry run to make sure we're removing the correct files. After the dry run, go ahead and remove the files found from tracking:
$ find . -type d -name ".svn" -exec "git rm -r --cached -n" {} \;
$ find . -type d -name ".svn" -exec "git rm -r --cached" {} \;
In my case, the project had tracked files that had been modified that I did not want to commit, so I couldn't simply run git add -u
to stage all the SVN files for a commit. Instead, I needed to use the output of git status
and run the git rm --cached
command on only those files that had a status of deleted:
$ git status | awk '/deleted/ {print $3}' | xargs git rm --cached
And there you have it! We have successfully removed all SVN files from Git without disturbing the rest of your project. Notice that we also used the --cached
flag as well. This will leave our files on the filesystem. If we want the files removed from the filesystem, we simply remove the --cached
flag.
Sources:
http://stackoverflow.com/questions/5870727/git-need-to-recursively-git-rm-the-contents-of-all-bin-and-obj-folders
http://stackoverflow.com/questions/492558/removing-multiple-files-from-a-git-repo-that-have-already-been-deleted-from-disk