Reputation: 66650
I have svn repo and I've removed a file somewhere in the past, how can I fetch that file from svn history? Let say I have right now rev 2000 and the file was removed in 1950.
Upvotes: 1
Views: 101
Reputation: 107090
svn log -v
and see if you can find the revision that removed the file.svn merge
or svn cp
to get the file back.Let's say you need to restore foo.txt
in trunk/proj/mydir
:
$ svn log -v $REPO/trunk/proj/mydir | less
Then you can use /D .*foo.txt
to search the less output for the file. You find that the file was deleted in revision 1235:
If that was the only thing revision 1235 did, or you decide you want to undo the rest of the stuff in that revision, you can use svn merge -c
:
$ svn co --depth=immediates $REPO/trunk/proj/mydir # No need to checkout sub directories too
$ cd mydir
$ svn merge -c -1235 . # Undoes the delete
$ svn commit -m "Restored file 'foo.txt' deleted in revision 1235"
Sometimes you simply want to restore the file, and not all the other changes in that revision. In that case, use the svn cp
command. You could do this without doing a checkout if you prefer:
$ svn cp -r1234 -m"Restored $foo.txt removed in rev 1235" \
$REPO/trunk/proj/mydir/foo.txt@1234 $REPO/trunk/myproj
Or you can do it though a checkout:
$ svn co --depth=immediates $REPO/trunk/proj/mydir # No need to checkout sub directories too
$ cd mydir
$ svn cp -r1234 foo.txt@1234 . # Undoes the delete
$ svn commit -m "Restored file 'foo.txt' deleted in revision 1235"
Note that I am using revision 1234 and not 1235 because the file was deleted in revision 1235 and doesn't exist in that revision. I use -r
to specify that I want revision 1234
of foo.txt
and I specify @1234
on the end of the URL to specify that the file exists in revision 1234
of the repository directory layout.
Upvotes: 1
Reputation: 42757
The svnbook has a topic about how to handle this.
It basically boils down to:
svn merge -c -revnum
to reinstate the file.svn copy file@revnum file
Upvotes: 2
Reputation: 241
If you just want to 'get' the file, you can do:
svn cat -r 1950 file > file
but as has been pointed out, this won't retrieve any of the file history, and will be seen by SVN as a completely new file.
Upvotes: 2