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.
You can use the git clean command to remove untracked files. The -fd command removes untracked directories and the git clean -fx command removes ignored and non-ignored files. You can remove untracked files using a . gitignore file.
Description. Recursively clean up the working copy, removing working copy locks and resuming unfinished operations. If you ever get a “working copy locked” error, run this command to remove stale locks and get your working copy into a usable state again.
NAME git-clean - Remove untracked files from the working tree OPTIONS -d Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With