11

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?

Zoe
  • 27,060
  • 21
  • 118
  • 148
ideasman42
  • 42,413
  • 44
  • 197
  • 320
  • (per @rodion) possible duplicate of [Automatically Remove Subversion Unversioned Files](http://stackoverflow.com/questions/239340/automatically-remove-subversion-unversioned-files) – Bert F Dec 23 '10 at 03:44
  • Possible duplicate of [this](http://stackoverflow.com/questions/239340/automatically-remove-subversion-unversioned-files) – rodion Dec 23 '10 at 03:41

5 Answers5

21

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 "{}"
Yuppi
  • 226
  • 2
  • 2
5

http://www.cuberick.com/2008/11/clean-up-your-subversion-working-copy.html

Here is what I do when I want my working copy to be identical to the repo:

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

That will remove all files that are out of sync with the repository. Then simply update to restore things you deleted and get up to date.

svn up

... Make sure that you've no edits or adds! Safer command might be:

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

... What about ignored files? E.g.

svn st --no-ignore
svn st --no-ignore | awk '{print $2}' | xargs rm -rf
svn st --no-ignore | grep '?' | awk '{print $2}' |xargs rm -f
Bert F
  • 85,407
  • 12
  • 106
  • 123
  • I am pretty sure that your commands with `awk` will fail if there are spaces in file names, because `awk` will only grab the second "field", which might be just the first word in a file/folder name. `rm` will fail to find the file/folder. – Jonathan Komar Aug 11 '15 at 08:50
3
svn status --no-ignore | grep '^[?I]' | awk '{print $2}' | xargs rm -rf

Let me explain.

Get the status of the files in a repository and prints them out one by one to standard output into an array

svn status

This includes files set to normally be ignored by svn

--no-ignore

Match lines that include either a ? or a I as a status. I means an ignored file and ? means a file not under svn control.

| grep '^[?I]'

This prints the second variable in the array which is the filename

| awk '{print $2}'

This removes the files with the printed filesnames

| xargs rm -rf

Cheers, Loop

LoopDuplicate
  • 453
  • 5
  • 7
2

Use this:

svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf

Obtained from commandlinefu.

cdhowie
  • 158,093
  • 24
  • 286
  • 300
-2

Delete every file that doesn't have the readonly attribute? Make sure you don't have things checked out beforehands...

  • 2
    thejohndonson to the rescue ))) And that is what question is about - how to do that automatically :-)) – zerkms Dec 23 '10 at 03:25
  • 1
    Since when does SVN apply the readonly attribute to all files in the checkout? I thought that kind of misbehavior was TFS territory. – cdhowie Dec 23 '10 at 03:30