Clean an svn checkout (remove non-svn files)

ideasman42 picture ideasman42 · Dec 23, 2010 · Viewed 10.4k times · Source

Id like to remove all files in my working copy that are not known in the svn repository.

Effectively as if I'd just made a clean checkout, but Id rather not have to re-download all files.

The closest think I've come to this is...

rm -rf `svn st | grep "^?" | cut -d" " -f8`

But this seems clunky and I don't totally trust it since inconsistency in output could remove dirs outside svn.

"svn export" isn't what Im looking for because I'm not cleaning the source to package it, I just want to remove cruft mostly (*.pyc, *.orig, *.rej, svn-commit.tmp, *.swp).

Is there a better way to do this besides making a clean checkout?

Answer

Yuppi picture Yuppi · Jun 30, 2011

Most solutions that are posted here fail to handle folders with whitespaces. This is why we use this one:

svn status --no-ignore | grep '^[?I]' |  sed "s/^[?I] //" | xargs -I{} rm -rf "{}"