我正在和一个朋友一起做一个项目,我想返回到我们代码的旧版本,并将其设置为当前版本。我该怎么做?

我在vs08上使用“anksvn”。

我的电脑上有我想要的版本,但提交失败;我得到的信息是 "提交失败,文件或目录已过期。"

我的电脑上也有subversion客户端。


当前回答

您只能在颠覆历史记录的头部提交新的更改。

你不能直接用你电脑上的好拷贝做任何事情的原因是,它的.svn文件夹知道它是过去的代码,所以在提交之前需要更新。

找到好的修订号并恢复

Find the revision number of the old copy you want. Get your current revision with: svn info --show-item revision # or svn log Or to check older versions of your project, use: svn update -r <earlier_revision_number> until you find the right revision number. Note down the good revision number (assuming 123 for examples below). Update to the latest revision: svn update Undo all the changes between the revision you want and the latest version: svn merge -r HEAD:123 . svn commit -m "Reverted to revision 123" (the same as Jon Skeet's answer above.)

如果你找不到修订号

如果你找不到旧的副本,你只想提交当前在你的电脑上的文件:

Make a copy of your good version (but without any .svn folders): cd .. rsync -ai --exclude=.svn project/ project-good/ Now make sure you have the latest version: cd project svn update # or make a fresh checkout svn checkout <url> Copy your good version over the top of the working copy. This command will copy, and also delete any files from the working tree that aren't in your good copy, but it won't affect the existing .svn folders. cd .. rsync -ai --exclude=.svn --delete project-good/ project/ If you don't have rsync, you can use cp -a but you will also need to delete any unwanted files manually. You should be able to commit what you have now. cd project svn commit -m "Reverted to good copy"

其他回答

我认为这是最合适的:

是否合并向后,例如,如果提交的代码包含修订 5612到5616版本,倒着合并。对我来说很管用。

例如:

svn merge -r 5616:5612 https://<your_svn_repository>/

它将包含一个合并的代码回到以前的修订,然后您可以提交它。

右键单击要恢复>>恢复或恢复到修订的最高层次结构

乔恩·斯基特的回答基本上就是一个简单的解决方案,但如果你和我一样,你可能想要一个解释。Subversion手册将其称为

择优挑选合并

从手册页。

This form is called a 'cherry-pick' merge: '-r N:M' refers to the difference in the history of the source branch between revisions N and M. A 'reverse range' can be used to undo changes. For example, when source and target refer to the same branch, a previously committed revision can be 'undone'. In a reverse range, N is greater than M in '-r N:M', or the '-c' option is used with a negative number: '-c -M' is equivalent to '-r M:'. Undoing changes like this is also known as performing a 'reverse merge'.


如果源是一个文件,则对该文件应用差异 文件(用于反向合并早期更改)。否则, 如果源是一个目录,那么目标默认为'.'。 在正常使用情况下,工作副本应该是最新的 修订,没有局部修改和切换子树。

例子:

svn merge -r 2983:289 path/to/file

这将用来自服务器的修订289替换本地副本[2983](根据上面的引用,它应该与服务器同步—您的责任)。更改发生在本地,这意味着如果您有一个干净的签出,那么可以在提交更改之前检查更改。

基本上你需要“向后合并”——将当前版本和以前版本之间的差异应用到当前版本(因此你最终会得到一个看起来像旧版本的工作副本),然后再次提交。例如,从150版(目前)回到140版:

svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"

Subversion红皮书对此有一个很好的章节。

有点老派

svn diff -r 150:140 > ../r140.patch
patch -p0 < ../r140.patch

然后是通常的

svn diff
svn commit