How to remove untracked files in SVN

How can I remove all untracked files from an SVN checkout with the svn command line tool? Git and Hg offer clean and purge commands for this purpose, but I can't find the corresponding command in SVN.

I don't care if I have to revert all my local modifications in the process (in which case I'd essentially want to restore my checkout to a pristine state) or whether local modifications to tracked files can remain intact; either situation is acceptable.


Solution 1:

There may be a built-in way, but if so, I don't know of it. However, something like the following should do the job:

svn st | grep '^?' | awk '{print $2}' | xargs rm -rf

(All unversioned files should appear in a line beginning with ? in an svn st.)

EDIT (@GearoidMurphy) It's challenging to get this snippet to work on a cygwin environment, as xargs treats the windows path slashes as escape sequences and has trouble parsing the '\r\n' line endings, below is my adapted solution of this perfectly valid answer:

svn st | grep '^?' | gawk '{printf(\"%s|\", $2)}' | xargs -d "|" -n1 C:\cygwin\bin\rm -r

Solution 2:

Since version 1.9, you can use the following:

svn cleanup . --remove-unversioned

See https://subversion.apache.org/docs/release-notes/1.9.html#svn-cleanup-options