Tuesday, January 13, 2009

copy svn working dir without svn hidden dirs and files?

I'm using svn to work on a JSP app which must be compiled and zipped into a fairly large .war file before deployment. I would like to be able to do this without having all the .svn directories and hidden files put into the archive as well. How can I just make a copy of my svn working directory (/home/user/progname) that doesn't include all svn's hidden files?



You could use the old "copy with tar" trick and pass it the --exclude option. The command would go something like this:
Code:
tar --exclude='.svn' -c -f - /path/to/sourcedir/* | (cd /path/to/destdir ; tar xfp -)
This command builds a tar archive of the files in sourcedir, excluding anything that matches the pattern '.svn' (i.e. the hidden Subversion directories). It writes the command to standard output, changes directory to destdir, and then extracts that standard output from a tar archive back to the filesystem.

Or, if you're too lazy for a command that complicated, you can just copy the entire directory and then delete the Subversion stuff with a plain-old:
Code:
find /path/to/destdir -name '.svn' -exec rm -r {} \;

-----------------------------------------------------------------------------------------
rysnc is a very powerful alternative to cp. It provides basic things like you want here, progress meters, copying to remote sites, a diff algorithm to efficiently maintain mirrors, compression, etc.

I think you want something like this:

Code:
rsync -r --exclude=.svn /home/user/progname/ /home/user/progname.copy
I almost always use -a (archive) instead of -r (recursive) because it means -r and more (see the man page). The trailing / on progname means `contents of' (otherwise progname.copy will contain progname and everything will be one more level down). Put a trailing / on .svn to only exlude directories with that name, instead of both directories and files with that name, if for some reason you had files named .svn that you wanted to keep in the copy.

rsync is awesome

No comments: