Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean an svn checkout (remove non-svn files)

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?

like image 533
ideasman42 Avatar asked Dec 23 '10 03:12

ideasman42


4 Answers

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 "{}"
like image 89
Yuppi Avatar answered Oct 02 '22 13:10

Yuppi


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
like image 29
Bert F Avatar answered Oct 04 '22 13:10

Bert F


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

like image 21
LoopDuplicate Avatar answered Oct 01 '22 13:10

LoopDuplicate


Use this:

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

Obtained from commandlinefu.

like image 41
cdhowie Avatar answered Oct 02 '22 13:10

cdhowie