我正在和一个朋友一起做一个项目,我想返回到我们代码的旧版本,并将其设置为当前版本。我该怎么做?
我在vs08上使用“anksvn”。
我的电脑上有我想要的版本,但提交失败;我得到的信息是 "提交失败,文件或目录已过期。"
我的电脑上也有subversion客户端。
我正在和一个朋友一起做一个项目,我想返回到我们代码的旧版本,并将其设置为当前版本。我该怎么做?
我在vs08上使用“anksvn”。
我的电脑上有我想要的版本,但提交失败;我得到的信息是 "提交失败,文件或目录已过期。"
我的电脑上也有subversion客户端。
当前回答
使用merge来撤销整个签入的标准方法非常有效,如果这是您想要做的。不过,有时您所要做的只是还原单个文件。没有合法的方法来做到这一点,但有一个hack:
使用svn log查找需要的版本。 使用svn的export子命令: SVN export http://url-to-your-file@123 /tmp/filename
(其中123是文件良好版本的修订号。)然后移动或复制该文件以覆盖旧文件。签入修改后的文件,就完成了。
其他回答
您只能在颠覆历史记录的头部提交新的更改。
你不能直接用你电脑上的好拷贝做任何事情的原因是,它的.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"
基本上你需要“向后合并”——将当前版本和以前版本之间的差异应用到当前版本(因此你最终会得到一个看起来像旧版本的工作副本),然后再次提交。例如,从150版(目前)回到140版:
svn update
svn merge -r 150:140 .
svn commit -m "Rolled back to r140"
Subversion红皮书对此有一个很好的章节。
这页上有很多危险的答案。请注意,从SVN版本1.6开始,执行更新-r可能会导致树冲突,这将迅速升级为可能丢失数据的kafkeresque噩梦,您需要在谷歌上搜索关于树冲突的信息。
恢复版本的正确方法是:
svn merge -r HEAD:12345 .
其中12345是版本号。别忘了这个点。
使用merge来撤销整个签入的标准方法非常有效,如果这是您想要做的。不过,有时您所要做的只是还原单个文件。没有合法的方法来做到这一点,但有一个hack:
使用svn log查找需要的版本。 使用svn的export子命令: SVN export http://url-to-your-file@123 /tmp/filename
(其中123是文件良好版本的修订号。)然后移动或复制该文件以覆盖旧文件。签入修改后的文件,就完成了。
同步到旧版本并提交。这应该能奏效。
这里还解释了撤消更改。