SVN版本回滚~

如果你在svn上对文件进行编辑作了修改,想撤销,那么有两种方法可以还原:
1) svn revert <yourfile>
2) 手动删除该文件,重新执行svn up(rm <yourfile>; svn up)

但是如果你已经提交了,想回滚到上一次的版本,那么可以按照下面的步骤操作:
# cat testfile 
1
2
3

1) 查看文件版本日志:
svn log testfile
-------------------------------------------------------------------------------------
r12147 | develop | 2010-12-21 18:42:54 +0800 (Tue, 21 Dec 2010) | 1 line

update testfile 02
-------------------------------------------------------------------------------------
r12146 | develop | 2010-12-21 18:40:34 +0800 (Tue, 21 Dec 2010) | 1 line

add testfile 01
-------------------------------------------------------------------------------------

2) 比较版本内容(压缩文件/二进制等文件就不用比了,此步骤非必须,这里仅为演示)
svn diff -r 12146:12147 testfile 
Index: testfile
===============================================
--- testfile    (revision 12146)
+++ testfile    (revision 12147)
@@ -1 +1,3 @@
 1
+2
+3

3) 合并(也就是回滚,关键步骤)
svn merge -r 12147:12146 testfile 
U    testfile

4) 查看合并后的结果(可选步骤,用以确认)
svn diff testfile 
Index: testfile
=============================================================
--- testfile    (revision 12153)
+++ testfile    (working copy)
@@ -1,3 +1 @@
 1
-2
-3
#如果到了这里你又突然不想回滚了,可以执行svn revert testfile撤销前面几个做的回滚操作.

 5) 提交回滚操作:(提交后就是回滚后的版本了)
# svn ci -m 'rollback to last revision:12146' testfile

# svn log testfile 
-------------------------------------------------------------------------------------
r12157 | develop | 2010-12-21 20:33:24 +0800 (Tue, 21 Dec 2010) | 1 line

rollback to rivision:12146
-------------------------------------------------------------------------------------
r12147 | develop | 2010-12-21 18:42:54 +0800 (Tue, 21 Dec 2010) | 1 line

update testfile 02
-------------------------------------------------------------------------------------
r12146 | develop | 2010-12-21 18:40:34 +0800 (Tue, 21 Dec 2010) | 1 line

add testfile 01
-------------------------------------------------------------------------------------

# cat testfile 
1

综上,最必要的就是3个步骤:
1. 确定版本号 svn log <file>
2. 合并 svn merge -r <latest revision>:<last revision> <file>
3. commit. svn ci -m 'rollback to last revision:' <file>

posted @ 2013-09-03 17:18  痴人指路  阅读(1922)  评论(0编辑  收藏  举报