views:

574

answers:

4

Here's a little SVN problem:

I create a directory locally:

$ svn mkdir output
A         output

I accidentally remove it:

rm -rf output

Now, how do I recreate it? I tried this:

$ svn mkdir output
svn: 'output' is already under version control

And this:

$ svn revert output
Reverted 'output'

But it's still not there.

UPDATE: People are suggesting that a simple mkdir output should have been enough after removing it. But in my SVN version that is not the case. It ignores the fact that there is an output/.svn directory that I also removed. Just mkdir output won't bring that one back, of course. So, somehow, SVN has to be involved in the recreation of that output directory. (I'm using SVN 1.4.6.)

+6  A: 

Remove it officially in SVN:

$  svn rm --force output
svn: 'output' does not exist

Then create it again:

$ svn mkdir output 
A         output

That output from svn remove above is a bit misleading. I thought the remove had failed, and it wouldn't change anything.

It's not the most intuitive approach here by SVN, but this way it works.

svn: 'output' does not exists is more a warning I think, 'svn rm' indeed removes the missing directory.From what I've seen, the --force parameter isn't necessary here
Sander Rijken
+2  A: 

Just mkdir output should have been enough.

Georg
I think that is not right -- see my Update.
+1  A: 

You could also try re-creating the directory with just mkdir.

svn mkdir creates the directory and also does the equivalent of svn add, but in one step.

So the reason you are having problems is because of the "add" that was done. Since you did not commit, revert will do nothing, and svn mkdir won't work since Subversion already has the directory listed for adding on the next commit (since your rm was outside of Subversion).

crashmstr
+1  A: 

The thing to understand about this is the distinction between the directories that are maintained by SVN and the ones maintained by your local file system.

The four commands, issued in your original post, do the following

  1. Tell SVN that you wish to add a directory called 'output' to the SVN repository - it responds by adding that information to its 'changelist'
  2. Remove the 'output' from your local file system - SVN is NOT aware of this taking place
  3. Tell SVN that you wish to add a directory called 'output' to the SVN repository - it complains because 'You told me that already!'
  4. Tell SVN that you've changed your mind about adding the 'output' directory - it obliges, by removing that information from its 'changelist'

If you had simply issued...

mkdir output

... as your step three, everything would have been fine - the directory was removed using the file system, so it should be restored using the file system. There is no reason to get SVN involved in the restoration and, as you found, attempting to do so simply confuses matters.

HTH

belugabob
wait, but what about the .svn subdirectory? That would have been lost in that case. I remove the directory that was created by SVN and just put a new one there that has no .svn in it. I don't think that would work.
@Dehmann, you are, indeed, correct. A good case of me not fully considering my answer before posting. I do hope, however, that you now appreciate the difference between SVN operations and file system operations. In future, when you get to step 2, simply issue steps 4 and 1, to recover the situation.
belugabob