How to remove untracked files in SVN

SvnVersion Control

Svn Problem Overview


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.

Svn Solutions


Solution 1 - Svn

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 - Svn

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

Solution 3 - Svn

The svn-clean script does precisely this, though it does rely on having perl installed. It will leave local modifications intact but will remove ignored files. Run with '-p' to preview the files that will be removed.

Solution 4 - Svn

This command should do the job, spaces and all (tried on OSX only):

svn status | grep '^\?' | sed 's/? *//' | xargs -I%  rm -fr %

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKerrek SBView Question on Stackoverflow
Solution 1 - SvnOliver CharlesworthView Answer on Stackoverflow
Solution 2 - SvnJulio Batista SilvaView Answer on Stackoverflow
Solution 3 - Svnthe_mandrillView Answer on Stackoverflow
Solution 4 - SvnRodrigo LopezView Answer on Stackoverflow