Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 205
Kerrek SB Avatar asked May 02 '12 13:05

Kerrek SB


People also ask

What command removes untracked?

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.

What is SVN cleanup command?

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.

How do I remove a single untracked file in git?

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.


2 Answers

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 
like image 152
Oliver Charlesworth Avatar answered Sep 23 '22 13:09

Oliver Charlesworth


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

like image 27
Julio Batista Silva Avatar answered Sep 20 '22 13:09

Julio Batista Silva