Why Subversion skips files which contain the @ sym

2019-03-09 16:26发布

问题:

when I try to execute command like this (from a command-line or Perl script - it doesn't matter):

svn revert "build\myfile@test.meta"

SVN skips this file and outputs:

Skipped 'build\myfile'

I tried doing:

svn revert "build\*.meta"

But it gives the same result.

I can revert these files from the GUI. And I can revert these files by doing (but it reverts more than I want):

svn revert --recursive "build"

Is there a workaround for this?

回答1:

The @ sign in filenames in Subversion actually has a special meaning - a pegged revision number. To quote the Subversion book:

The perceptive reader is probably wondering at this point whether the peg revision syntax causes problems for working copy paths or URLs that actually have at signs in them. After all, how does svn know whether news@11 is the name of a directory in my tree or just a syntax for “revision 11 of news”? Thankfully, while svn will always assume the latter, there is a trivial workaround. You need only append an at sign to the end of the path, such as news@11@. svn cares only about the last at sign in the argument, and it is not considered illegal to omit a literal peg revision specifier after that at sign. This workaround even applies to paths that end in an at sign—you would use filename@@ to talk about a file named filename@.

So, you should append an @ sign to filenames in scripts, like this:

svn revert "build\myfile@test.meta@"


回答2:

Just to add to the above correct answer, if you have lots of files with the "@" symbol in their name that you want to process in a batch (i.e. use * wildcard), you can do something like this in OS X Terminal (or any Linux box really):

find . -name "*@*" | xargs -I % svn add %@

The above command will use the find utility to list out each file with @ in its filename and then pipe the path to the file to SVN using XARGS. XARGS will replace each occurrence of % with the path and append the special "@" at the end of the filename so that SVN will accept it.

Hope this helps - I had to whack my head for a bit to add the gazzilion @2x.png files that were needed for my app to be upgraded for iOS4.0



回答3:

Just tested it properly on windows using the cmd.exe shell - enclosing the name in double quotes works:

ctmkx> svn revert "trunk\foo@bar.txt"
Reverted 'trunk\foo@bar.txt'


回答4:

What operating system? If it is a *nix system, try quoting your file with 'single@quotes'.