Undo Add in Subversion

A small but useful tip, due to the slightly non-obviousness of it. Let's say you've just scheduled a bunch of files to be added to your Subversion repository with a good old svn add *.c. But then you realise you didn't want to add all of them - some of them need to be put elsewhere. So you need to "undo" the add operation.

Okay, well the obvious thing is to use the opposite of add, which is delete. But that only works if the files are already in the repository. If the file is local and new (ie. not yet in the repo), you get this rather cryptic error message:

% svn rm F2_DATA_FORMATS.html
svn: Use --force to override this restriction
svn: 'F2_DATA_FORMATS.html' has local modifications

This actually has no effect on the file specified or the repo. Now wait! If you're feeling tempted to use the --force flag, please note that this will actually remove the local copy (which never got added to the repo!) as well as removing the scheduled 'add'. So you really probably don't actually want to do that, as you will lose it. (Ask me how I discovered that one.)

It turns out that a simple svn revert F2_DATA_FORMATS.html is all that is required, to undo the add and let you move the file into its proper place without dangling references.

As a general rule, I always advise against using wildcards in svn operations. It might take longer to explicitly identify the files you are working with, but it is far safer.

Of course, if you are working within an editor such as Emacs, the psvn module provides an excellent interface to your repo. But sometimes the command-line interface is just what you need for a bit of repo maintenance.