Tuesday, November 25, 2008

Deep Clean Your Subversion Working Copy


awk and xargs. Deep cleaning action for those hard to reach places. Sometimes you just want your subversion working copy to be clean. If you have files with changes you can just revert things, but what about files that aren't under version control? Those are harder to clean up, especially if they are spread all over the place. 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

5 comments:

Julian said...

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

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

Shlomo said...

Good point Julian. You would only want to use my command if you were sure there were no important modifications in your working copy. Some svn st and svn diffing would be in order before pulling the trigger on mr. clean :)

A Booth said...

http://generaldevelopertips.blogspot.com/2009/08/subversion-stripping-working-copy.html

craig said...

What about ignored files? E.g.

svn st --no-ignore

Carlo said...

I've wrapped this up in a script which lets you preview the files it's about to delete and which has a switch for whether to include ignored files (see craig's comment).