tags:

views:

186

answers:

3

I have inadvertently svn-deleted a file with svn del --targets del.txt. Now, I'd like to recover that file with svn cat myPreciousFile.txt@4130 > myPreciousFile.txt, but svn gives me a warning that myPreciousFile.txt is not under version control. A svn cat -r 4130 myPreciousFile.txt > myPreciousFile.txt didn't work, either.

Can someone please tell me how I'd go about recovering this file again?

EDIT

Ok, I have tried it with svn merge, but it still doesn't work. Here's what I did (file names altered to protect the guilty...):

f:\path\to\dev\dir> svn diff -r 4250:4251 --summarize
D      file_one.tyb
D      file_two.tyb
D      myPreciousFile.txt

I interpret this output as "myPreciousFile was deleted in revision 4251". So, I tried it with svn merge:

f:\path\to\dev\dir> svn merge-c -4251 myPreciousFile.txt

And svn still warns me about myPreciousFile.txt not being under version control. (Same error message btw with svn merge-c -4250 myPreciousFile.txt.

+3  A: 
svn merge -c -<revision where you deleted the file> .

So if the delete occurred during revision 4131, you would:

svn merge -c -4131 .
             ^ the negative on the revision is important

In response to the question edit:

You shouldn't specify the filename. Just do . and your file will be restored. Then svn revert the changes that you don't want back.

Sean Bright
`svn merge` is the operation of applying some bunch of changesets (diffs) to the particular file. in this case you cannot use the command in the way you displayed.
zerkms
@zerkms: you are not correct. the command works exactly as typed in the tests i ran before posting my response.
Sean Bright
@zerkms: http://svnbook.red-bean.com/nightly/en/svn-book.html#svn.branchmerge.basicmerging.undo
Sean Bright
@Sean: --- Reverse-merging r28 into '.': C file.txtSummary of conflicts: Tree conflicts: 1
zerkms
and documentation is talking about reverting **changes**. it said about how to **undo changes** of file.
zerkms
@zerkms: a deletion is a change.
wds
your most recent comment doesn't make grammatical sense so i am not sure what you are trying to say. regardless, from the documentation that i linked: "One option is to use svn merge to apply revision 808 'in reverse.' (...) This would have the effect of re-adding real.c as a local modification. The file would be scheduled for addition, and after a commit, the file would again exist in HEAD."
Sean Bright
@wds: i know :-) but documentation is talking about another kind of changes. anyway, as you can see it does not work for me.
zerkms
I added another answer with demonstration that it doesn't work. you can comment there.
zerkms
oops, my miss. i had to specify the revision at which file was deleted. sorry guys. everything is good.
zerkms
anyway, my accepted answer is more correct, due to it keeps the previous history.
zerkms
@zerkms: rolling back the delete will also keep the previous history. Both answers are correct.
wds
yeah, i'm not sure why this is still in question.
Sean Bright
hmmmmmm...... i was totally wrong :-S don't know why i thought that `merge` will not keep logs... `merge` is just a `get diff+apply diff` - how could it track the changes?
zerkms
+2  A: 

You must not restore file with cat.

The proper way of doing this is copy

svn copy http://server/full/path/to/myPreciousFile.txt@4130 .

after that commit current directory. with this solution you will keep the complete history of changings of that file.

zerkms
A: 

As others have suggested, you can do a reverse merge to get your file back. I suspect that your command is failing because you also specified the specific file you want to merge, and that file isn't under source control anymore. I can see two options for how to recover it.

Merge and revert

Reverse merge the whole commit, then revert the files you really did want to delete. Here's the example you gave:

f:\path\to\dev\dir> svn diff -r 4250:4251 --summarize
D      file_one.tyb
D      file_two.tyb
D      myPreciousFile.txt

Do the reverse merge:

f:\path\to\dev\dir> svn merge -c -4251

Then revert the two you really meant to delete:

f:\path\to\dev\dir> svn revert file_one.tyb
f:\path\to\dev\dir> svn revert file_two.tyb

Copy

Use the copy command suggested by zerkms to copy the specific file you want out of the repository history.

svn copy http://server/full/path/to/myPreciousFile.txt@4130 .
Don Kirkby