SVN: How to re-create a directory that's created but not committed yet
Question
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.)
Solution
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.
OTHER TIPS
Just mkdir output
should have been enough.
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
- Tell SVN that you wish to add a directory called 'output' to the SVN repository - it responds by adding that information to its 'changelist'
- Remove the 'output' from your local file system - SVN is NOT aware of this taking place
- Tell SVN that you wish to add a directory called 'output' to the SVN repository - it complains because 'You told me that already!'
- 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
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).