转:http://blog.chinaunix.net/uid-346158-id-2131188.html
root@bananapi /home/pi/myproject
# touch ceshi.txt
root@bananapi /home/pi/myproject
# svn status
? ceshi.txt
root@bananapi /home/pi/myproject
# svn add ceshi.txt
A ceshi.txt
root@bananapi /home/pi/myproject
# svn status
A ceshi.txt
root@bananapi /home/pi/myproject
# svn commit -m '' ceshi.txt
Adding ceshi.txt
Transmitting file data .s
Committed revision 17.
root@bananapi /home/pi/myproject
# svn status
root@bananapi /home/pi/myproject
# echo "test">>ceshi.txt
root@bananapi /home/pi/myproject
# svn status
M ceshi.txt
root@bananapi /home/pi/myproject
# svn diff ceshi.txt
Index: ceshi.txt
===================================================================
--- ceshi.txt (revision 17)
+++ ceshi.txt (working copy)
@@ -0,0 +1 @@
+test
root@bananapi /home/pi/myproject
# svn status
M ceshi.txt
root@bananapi /home/pi/myproject
# svn revert ceshi.txt
Reverted 'ceshi.txt'
root@bananapi /home/pi/myproject
# svn status
root@bananapi /home/pi/myproject
# svn diff ceshi.txt
root@bananapi /home/pi/myproject
# echo "ceshi">>ceshi.txt
root@bananapi /home/pi/myproject
# svn status
M ceshi.txt
root@bananapi /home/pi/myproject
# svn commit -m 'ceshi' ceshi.txt
Sending ceshi.txt
Transmitting file data .
Committed revision 18.
root@bananapi /home/pi/myproject
# svn status
root@bananapi /home/pi/myproject
# svn log ceshi.txt
------------------------------------------------------------------------
r18 | bananapi | 2017-04-21 23:46:52 +0800 (Fri, 21 Apr 2017) | 1 line
ceshi
------------------------------------------------------------------------
r17 | bananapi | 2017-04-21 23:45:08 +0800 (Fri, 21 Apr 2017) | 1 line
------------------------------------------------------------------------
root@bananapi /home/pi/myproject
# svn diff -r 17:18 ceshi.txt
Index: ceshi.txt
===================================================================
--- ceshi.txt (revision 17)
+++ ceshi.txt (revision 18)
@@ -0,0 +1 @@
+ceshi
root@bananapi /home/pi/myproject
# svn cat -r 18 ceshi.txt
ceshi
root@bananapi /home/pi/myproject
# svn cat -r 17 ceshi.txt
root@bananapi /home/pi/myproject
# svn merge -r 18:17 ceshi.txt
--- Reverse-merging r18 into 'ceshi.txt':
U ceshi.txt
--- Recording mergeinfo for reverse merge of r18 into 'ceshi.txt':
U ceshi.txt
--- Eliding mergeinfo from 'ceshi.txt':
U ceshi.txt
root@bananapi /home/pi/myproject
# cat ceshi.txt
root@bananapi /home/pi/myproject
# svn status
! 1.php
! 2.php
M ceshi.txt
! 1
root@bananapi /home/pi/myproject
# svn commit -m
root@bananapi /home/pi/myproject
# svn diff ceshi.txt
Index: ceshi.txt
===================================================================
--- ceshi.txt (revision 18)
+++ ceshi.txt (working copy)
@@ -1 +0,0 @@
-ceshi
root@bananapi /home/pi/myproject
# svn commit -m '' ceshi.txt
Sending ceshi.txt
Transmitting file data .
Committed revision 19.
root@bananapi /home/pi/myproject
# svn st
! 1.php
! 2.php
! 1
root@bananapi /home/pi/myproject
# svn log ceshi.txt
------------------------------------------------------------------------
r19 | bananapi | 2017-04-21 23:55:11 +0800 (Fri, 21 Apr 2017) | 1 line
------------------------------------------------------------------------
r18 | bananapi | 2017-04-21 23:46:52 +0800 (Fri, 21 Apr 2017) | 1 line
ceshi
------------------------------------------------------------------------
r17 | bananapi | 2017-04-21 23:45:08 +0800 (Fri, 21 Apr 2017) | 1 line
------------------------------------------------------------------------
root@bananapi /home/pi/myproject
# svn diff -r 17:19 ceshi.txt
如果你在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>