I deleted a file from a repo and now want to put it back. The best I can figure out is to:
That just smells bad and it looses all history to boot. There has got to be a better way to do this. I have already looked in The SVN Book but didn't find anything and am now looking down the SVN tag list.
This question is related to
svn
tortoisesvn
restore
For completeness, this is what you would have found in the svn book, had you known what to look for. It's what you've discovered already:
Same thing, from the more recent (and detailed) version of the book:
If you're using Tortoise SVN, you should be able to revert changes from just that revision into your working copy (effectively performing a reverse-merge), then do another commit to re-add the file. Steps to follow are:
With Tortoise SVN:
If you haven't committed your changes yet, you can do a revert on the parent folder where you deleted the file or directory.
If you have already committed the deleted file, then you can use the repository browser, change to the revision where the file still existed and then use the command Copy to... from the context menu. Enter the path to your working copy as the target and the deleted file will be copied from the repository to your working copy.
You should be able to just check out the one file you want to restore. Try something like svn co svn://your_repos/path/to/file/you/want/to/restore@rev
where rev
is the last revision at which the file existed.
I had to do exactly this a little while ago and if I remember correctly, using the -r
option to svn
didn't work; I had to use the :rev
syntax. (Although I might have remembered it backwards...)
If you're using Tortoise SVN, you should be able to revert changes from just that revision into your working copy (effectively performing a reverse-merge), then do another commit to re-add the file. Steps to follow are:
The easiest way I have been able to restore files and not lose revision history is using SVN copy, the merge example above to me seems like a more complex way to achieve the same thing. Why is there a need to merge when you simply want to restore a revision?
I use the following in this instance and it works quite well.
svn copy -m 'restoring file' -r <rev_number_file_to_restore> http://from/file.cs http://pathTo/file.cs
I always seem to use svn copy
as a server operation so not sure if it works with two working paths.
If you're using Tortoise SVN, you should be able to revert changes from just that revision into your working copy (effectively performing a reverse-merge), then do another commit to re-add the file. Steps to follow are:
You should be able to just check out the one file you want to restore. Try something like svn co svn://your_repos/path/to/file/you/want/to/restore@rev
where rev
is the last revision at which the file existed.
I had to do exactly this a little while ago and if I remember correctly, using the -r
option to svn
didn't work; I had to use the :rev
syntax. (Although I might have remembered it backwards...)
For completeness, this is what you would have found in the svn book, had you known what to look for. It's what you've discovered already:
Same thing, from the more recent (and detailed) version of the book:
The problem with doing an svn merge as suggested by Sean Bright is that is reintroduces other changes made in the same revision as the deletion. An svn copy is a more targeted operation that will only affect the deleted files.
Using Tortoise SVN you can resurrect a file that has been deleted from your working copy directory and from later SVN revisions, via a svn copy as follows:
The deleted file will now be in the working copy folder. To re-add it back to SVN, right click on the restored file and select SVN Commit.
NB: This method will preserve the previous history of the restored file, however to see the prior history in the TortoiseSVN log you need to make sure "Stop on copy/rename" is unchecked in the Log messages dialog.
With Tortoise SVN:
If you haven't committed your changes yet, you can do a revert on the parent folder where you deleted the file or directory.
If you have already committed the deleted file, then you can use the repository browser, change to the revision where the file still existed and then use the command Copy to... from the context menu. Enter the path to your working copy as the target and the deleted file will be copied from the repository to your working copy.
You should be able to just check out the one file you want to restore. Try something like svn co svn://your_repos/path/to/file/you/want/to/restore@rev
where rev
is the last revision at which the file existed.
I had to do exactly this a little while ago and if I remember correctly, using the -r
option to svn
didn't work; I had to use the :rev
syntax. (Although I might have remembered it backwards...)
I always seem to use svn copy as a server operation so not sure if it works with two working paths.
Here is an example of restoring a deleted file into a local working copy of the project:
svn copy https://repos/project/modules/module.js@3502 modules/module.js
While being inside the project directory. This works as well for restoring entire directories.
Use the Tortoise SVN copy functionality to revert commited changes:
Hope that helps
The problem with doing an svn merge as suggested by Sean Bright is that is reintroduces other changes made in the same revision as the deletion. An svn copy is a more targeted operation that will only affect the deleted files.
Using Tortoise SVN you can resurrect a file that has been deleted from your working copy directory and from later SVN revisions, via a svn copy as follows:
The deleted file will now be in the working copy folder. To re-add it back to SVN, right click on the restored file and select SVN Commit.
NB: This method will preserve the previous history of the restored file, however to see the prior history in the TortoiseSVN log you need to make sure "Stop on copy/rename" is unchecked in the Log messages dialog.
If you're using Tortoise SVN, you should be able to revert changes from just that revision into your working copy (effectively performing a reverse-merge), then do another commit to re-add the file. Steps to follow are:
Use the Tortoise SVN copy functionality to revert commited changes:
Hope that helps
With Tortoise SVN:
If you haven't committed your changes yet, you can do a revert on the parent folder where you deleted the file or directory.
If you have already committed the deleted file, then you can use the repository browser, change to the revision where the file still existed and then use the command Copy to... from the context menu. Enter the path to your working copy as the target and the deleted file will be copied from the repository to your working copy.
For completeness, this is what you would have found in the svn book, had you known what to look for. It's what you've discovered already:
Same thing, from the more recent (and detailed) version of the book:
The easiest way I have been able to restore files and not lose revision history is using SVN copy, the merge example above to me seems like a more complex way to achieve the same thing. Why is there a need to merge when you simply want to restore a revision?
I use the following in this instance and it works quite well.
svn copy -m 'restoring file' -r <rev_number_file_to_restore> http://from/file.cs http://pathTo/file.cs
I always seem to use svn copy
as a server operation so not sure if it works with two working paths.
I always seem to use svn copy as a server operation so not sure if it works with two working paths.
Here is an example of restoring a deleted file into a local working copy of the project:
svn copy https://repos/project/modules/module.js@3502 modules/module.js
While being inside the project directory. This works as well for restoring entire directories.
With Tortoise SVN:
If you haven't committed your changes yet, you can do a revert on the parent folder where you deleted the file or directory.
If you have already committed the deleted file, then you can use the repository browser, change to the revision where the file still existed and then use the command Copy to... from the context menu. Enter the path to your working copy as the target and the deleted file will be copied from the repository to your working copy.
You should be able to just check out the one file you want to restore. Try something like svn co svn://your_repos/path/to/file/you/want/to/restore@rev
where rev
is the last revision at which the file existed.
I had to do exactly this a little while ago and if I remember correctly, using the -r
option to svn
didn't work; I had to use the :rev
syntax. (Although I might have remembered it backwards...)
Source: Stackoverflow.com