Subversion中如何RollBack版本

在使用TortoiseSVN的时候,不小心CheckIn错了东西,想RollBack回上一次代码。
经过搜索发现如下方法:
第一种方法: 使用TortoiseSVN进行回滚. 很明显, 这种方法只适用于windows平台. 以下摘自 TortoiseSVN文档:

B.4. 回滚版本库里的版本

B.4.1. 使用版本日志对话框

如果想恢复某个版本或者版本范围的变更,最简单的方法是使用版本日志对话框。这种方法也可以用来撤销最近的若干次变更,把以前的某个版本变成最新版。

  1. 选中想要恢复变更的文件或者文件夹。如果想要恢复所有的变更,需要选中最顶层的文件夹。

  2. 选择TortoiseSVN显示日志,显示出版本列表。有可能需要使用全部显示或者下100 按钮,把想要恢复的版本显示出来。

  3. 选中想要恢复的版本。如果想要恢复一个版本范围,选中想要恢复的第一个版本,按住shift键,然后选中想要恢复的最后一个版本。注意,当恢复多个版本的时候,这些版本必须在列表中是连续的。用鼠标右键点击选中的版本(段),然后选择右键菜单恢复这些版本的变更

  4. 如果想要把以前的某个版本变成最新版本,右键点击选中的版本(范围),然后选择右键菜单恢复到此版本。就能够撤销被选中版本后面所有的变更。

工作拷贝已经恢复到了变更以前的状态。检查恢复后的结果,然后提交变更。

B.4.2. 使用合并对话框

如果要撤销更大版本范围的变更,可以使用合并对话框。上一个方法在后台使用了合并的机制,在这个方法里我们直接使用合并功能。

  1. 在工作拷贝上选择TortoiseSVN合并

  2. 起始:文本框里输入想要恢复的变更所在的分支或标签的URL。它也将作为默认URL。

  3. 起始版本文本框里输入当前工作拷贝的版本号。如果能够保证没有其他人会提交变更,可以使用最新版本

  4. 确认使用“起始:”的 URL检查框处于被选中的状态。

  5. 结束版本里输入想要恢复到的版本号。比如,想要恢复的最小版本号的一个版本号。

  6. 点击合并按钮完成合并。

工作拷贝已经恢复到了变更以前的状态。检查恢复后的结果,然后提交变更。

B.4.3. 使用svndumpfilter

因为TortoiseSVN绝不会丢弃数据,所以那些被回滚的版本仍然以中间版本的形式被保留在版本库里。只是最新版本已经回到了以前的状态。如果想让版本库里的某些版本彻底消失,擦去这些版本曾经存在过的所有痕迹,就必须采取更极端的手段。不推荐使用这种方法,除非有很好的理由。比如某人向一个公开的版本库里提交了一份机密文件。

从版本库里删除数据的唯一方法就是使用svnadmin这个Subversion命令行工具。具体如何实现请参考Subversion手册

第二种方法: 使用SubVersion自带的svn merge 命令. 这种方法适用于任何能使用SubVersion的平台. 以下摘自 <使用SubVersion进行版本控制> 4.4.2节:

svn merge另一个常用的做法是取消已经做得提交,假设你愉快的在/calc/trunk工作,你发现303版本对integer.c的修改完全错了,它不应该被提交,你可以使用svn merge来“取消”这个工作拷贝上所作的操作,然后提交本地修改到版本库,你要做得只是指定一个相反的区别:

$ svn merge -r 303:302 http://svn.example.com/repos/calc/trunkU  integer.c$ svn statusM  integer.c$ svn diff…# verify that the change is removed…$ svn commit -m "Undoing change committed in r303."Sending        integer.cTransmitting file data .Committed revision 350.

我们可以把版本库修订版本想象成一组修改(一些版本控制系统叫做修改集),通过-r选项,你可以告诉svn merge来应用修改集或是一个修改集范围到你的工作拷贝,在我们的情况例子里,我们使用svn merge合并修改集#303到工作拷贝。

记住回滚修改和任何一个svn merge命令都一样,所以你应该使用svn status或是svn diff来确定你的工作处于期望的状态中,然后使用svn commit来提交,提交之后,这个特定修改集不会反映到HEAD版本了。

继续,你也许会想:好吧,这不是真的取消提交吧!是吧?版本303还依然存在着修改,如果任何人取出calc的303-349版本,他还会得到错误的修改,对吧?

是的,这是对的。当我们说“删除”一个修改时,我们只是说从HEAD删除,原始的修改还保存在版本库历史中,在多数情况下,这是足够好的。大多数人只是对追踪HEAD版本感兴趣,在一些特定情况下,你也许希望毁掉所有提交的证据(或许某个人提交了一个秘密文件),这不是很容易的,因为Subversion设计用来不丢失任何信息,每个修订版本都是不可变的目录树 ,从历史删除一个版本会导致多米诺效应,会在后面的版本导致混乱甚至会影响所有的工作拷贝。 [9]

解释一下,  svn merge -r 303:302 http://svn.example.com/repos/calc/trunk 这个命令是把当前目录当作工作拷贝.  如果想指定工作拷贝路径(如: c:/test), 则命令变成以下:

  svn merge -r 303:302 http://svn.example.com/repos/calc/trunk  c:/test

Roll back revisions in the repository

Use the revision log dialog

The easiest way to revert the changes from a single revision, or from a range of revisions, is to use the revision log dialog. This is also the method to use of you want to discard recent changes and make an earlier revision the new HEAD.

  1. Select the file or folder in which you need to revert the changes. If you want to revert all changes, this should be the top level folder.

  2. Select TortoiseSVNShow Log to display a list of revisions. You may need to use Get All or Next 100 to show the revision(s) you are interested in.

  3. Select the revision you wish to revert. If you want to undo a range of revisions, select the first one and hold the shift key while selecting the last one. Note that for multiple revisions, the range must be unbroken with no gaps. Right click on the selected revision(s), then select Context MenuRevert changes from this revision.

  4. Or if you want to make an earlier revision the new HEAD revision, right click on the selected revision(s), then select Context MenuRevert to this revision. This will discard all changes after the selected revision.

You have reverted the changes within your working copy. Check the results, then commit the changes.

Use the merge dialog

To undo a larger range of revisions, you can use the Merge dialog. The previous method uses merging behind the scenes; this method uses it explicitly.

  1. In your working copy select TortoiseSVNMerge.

  2. In the From: field enter the full folder url of the branch or tag containing the changes you want to revert in your working copy. This should come up as the default URL.

  3. In the From Revision field enter the revision number that you are currently at. If you are sure there is no-one else making changes, you can use the HEAD revision.

  4. make sure the Use "From:" URL checkbox is checked.

  5. In the To Revision field enter the revision number that you want to revert to, ie. the one before the first revision to be reverted.

  6. Click OK to complete the merge.

You have reverted the changes within your working copy. Check the results, then commit the changes.

Use svndumpfilter

Since TortoiseSVN never loses data, your “rolled back” revisions still exist as intermediate revisions in the repository. Only the HEAD revision was changed to a previous state. If you want to make revisions disappear completely from your repository, erasing all trace that they ever existed, you have to use more extreme measures. Unless there is a really good reason to do this, it is not recommended. One possible reason would be that someone committed a confidential document to a public repository.

The only way to remove data from the repository is to use the Subversion command line tool svnadmin. You can find a description of how this works in the Subversion Book .

 信息来源:
http://blog.csdn.net/riag/archive/2007/05/30/1630819.aspx
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-howto-rollback.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值