Adding files that begin with a hyphen or dash to Subversion (SVN)

(1 minute read)

After working on a large project for about two months I was going through my usual pre-QA checklist and noticed that I had about 100 files that were converted over from the clients site that were not listed in svn. I tried adding them one by one but kept getting the error “svn: invalid option character”. It turns out SVN doesn’t like files that begin with dashes (or is it a hyphen?) which is understandable since it thinks it’s an argument.

I ended up trying just about everything… quotes, single quotes, back slashes etc. Nothing worked. Then I stopped by my local system admin (Dean, not Josh. Just in case you are taking notes) and he game me this handy bit of code that added my troublesome files to svn.

find . -name "\-*" -exec svn add {} \;

It worked like a charm (upon further thought I have no idea how charms work) and now ALL of my files are happily living in SVN.