svn命令行使用说明(转)

转来的,方便自己学习,懒得到处找,放到这里!

0、查看帮助
命令: svn help
1、同步(checkout)服务器数据到本地
命令: svn checkout [directory]
svn co [directory]
例:把 https://svn.test.cn/book/network/ 目录同步到本地的 /usr/local/svn/book/network 目录
# cd /usr/local/svn/book
# svn checkout https://svn.test.cn/book/network/…
(R)eject, accept (t)emporarily or accept (p)ermanently? t

Password for ‘wandering’: <回车> # wandering是我当前登录系统的帐号
Authentication realm: book Subversion Repository
Username: jack
Password for ‘jack’:

2、提交(commit)本地文档到服务器
命令: svn commit -m “” [directory|file]
svn ci -m “” [directory|file]
例:把 /usr/local/svn/book/network/tcpip.txt 提交到服务器,前提是服务器上已经有此文件。
# cd /usr/local/svn/book/network/
# svn commit -m “” # -m是记录的log信息,可以为空

一般情况下,只要在需要更新的数据文件所在的目录执行 svn ci -m “” 即可。

3、更新(update)服务器数据到本地
命令: svn update [directory|file]
svn up [directory|file]
例:把 https://svn.test.cn/book/network/ 目录中的内容更新到本地
# cd /usr/local/svn/book/network
# cd update

4、查看日志
命令: svn log [directory|file]
例:查看 /usr/local/svn/book/network 目录的修改日志
方法一:
# cd /usr/local/svn/book/network
# svn log
方法二:
# svn log /usr/local/svn/book/network

5、增加(add)本地数据到服务器
命令: svn add

开发人员常用命令

(1) 导入项目

$ cd ~/project
$ mkdir -p svntest/{trunk,branches,tags}
$ svn import svntest https://localhost/test/svntest –message “Start project”

$ rm -rf svntest

我们新建一个项目svntest,在该项目下新建三个子目录:trunk,开发主干;branches,开发分支;tags,开发阶段性标签。然后导入到版本库test下,然后把svntest拿掉。

(2) 导出项目

$ svn checkout https://localhost/test/svntest/trunk

修订版本号的指定方式是每个开发人员必须了解的,以下是几个参考例子,说明可参考svn推荐书。

$ svn diff –revision PREV:COMMITTED foo.c
# shows the last change committed to foo.c

$ svn log –revision HEAD
# shows log message for the latest repository commit

$ svn diff –revision HEAD
# compares your working file (with local changes) to the latest version
# in the repository

$ svn diff –revision BASE:HEAD foo.c
# compares your “pristine” foo.c (no local changes) with the
# latest version in the repository

$ svn log –revision BASE:HEAD
# shows all commit logs since you last updated

$ svn update –revision PREV foo.c
# rewinds the last change on foo.c
# (foo.c’s working revision is decreased)

$ svn checkout –revision 3
# specified with revision number

$ svn checkout –revision {2002-02-17}
$ svn checkout –revision {15:30}
$ svn checkout –revision {15:30:00.200000}
$ svn checkout –revision {“2002-02-17 15:30”}
$ svn checkout –revision {“2002-02-17 15:30 +0230”}
$ svn checkout –revision {2002-02-17T15:30}
$ svn checkout –revision {2002-02-17T15:30Z}
$ svn checkout –revision {2002-02-17T15:30-04:00}
$ svn checkout –revision {20020217T1530}
$ svn checkout –revision {20020217T1530Z}
$ svn checkout –revision {20020217T1530-0500}

(3) 日常指令

$ svn update

$ svn add foo.file
$ svn add foo1.dir
$ svn add foo2.dir –non-recursive
$ svn delete README
$ svn copy foo bar
$ svn move foo1 bar1

$ svn status
$ svn status –verbose
$ svn status –verbose –show-updates
$ svn status stuff/fox.c

$ svn diff
$ svn diff > patchfile

$ svn revert README
$ svn revert

修改冲突发生时,会生成三个文件:.mine, .rOLDREV, .rNEWREV。比如:

$ ls -l
sandwich.txt
sandwich.txt.mine
sandwich.txt.r1
sandwich.txt.r2

解决修改冲突方式之一:修改冲突的文件sandwich.txt,然后运行命令:

$ svn resolved sandwich.txt

方式之二:用库里的新版本覆盖你的修改:

$ cp sandwich.txt.r2 sandwich.txt
$ svn resolved sandwich.txt

方式之三:撤销你的修改,这种方式不需要运行resolved子命令:

$ svn revert sandwich.txt
Reverted ‘sandwich.txt’
$ ls sandwich.*
sandwich.txt

确保没问题后,就可以提交了。

$ svn commit –message “Correct some fatal problems”
$ svn commit –file logmsg
$ svn commit

(4) 检验版本历史

$ svn log
$ svn log –revision 5:19
$ svn log foo.c
$ svn log -r 8 -v

$ svn diff
$ svn diff –revision 3 rules.txt
$ svn diff –revision 2:3 rules.txt
$ svn diff –revision 4:5 http://svn.red-bean.com/repos/example/trunk/text/rules.txt

$ svn cat –revision 2 rules.txt
$ svn cat –revision 2 rules.txt > rules.txt.v2

$ svn list http://svn.collab.net/repos/svn
$ svn list –verbose http://svn.collab.net/repos/svn

$ svn checkout –revision 1729 # Checks out a new working copy at r1729

$ svn update –revision 1729 # Updates an existing working copy to r1729

(5) 其他有用的命令

svn cleanup

为失败的事务清场。

(6) 分支和合并

建立分支方法一:先checkout然后做拷贝,最后提交拷贝。

$ svn checkout http://svn.example.com/repos/calc bigwc
A bigwc/trunk/
A bigwc/trunk/Makefile
A bigwc/trunk/integer.c
A bigwc/trunk/button.c
A bigwc/branches/
Checked out revision 340.

$ cd bigwc
$ svn copy trunk branches/my-calc-branch
$ svn status
A + branches/my-calc-branch

$ svn commit -m “Creating a private branch of /calc/trunk.”
Adding branches/my-calc-branch
Committed revision 341.

建立分支方法二:直接远程拷贝。

$ svn copy http://svn.example.com/repos/calc/trunk \
http://svn.example.com/repos/calc/branches/my-calc-branch \
-m “Creating a private branch of /calc/trunk.”

Committed revision 341.

建立分支后,你可以把分支checkout并继续你的开发。

$ svn checkout http://svn.example.com/repos/calc/branches/my-calc-branch

假设你已经checkout了主干,现在想切换到某个分支开发,可做如下的操作:

$ cd calc
$ svn info | grep URL
URL: http://svn.example.com/repos/calc/trunk
$ svn switch http://svn.example.com/repos/calc/branches/my-calc-branch
U integer.c
U button.c
U Makefile
Updated to revision 341.
$ svn info | grep URL
URL: http://svn.example.com/repos/calc/branches/my-calc-branch

合并文件的命令参考:

$ svn diff -r 343:344 http://svn.example.com/repos/calc/trunk
$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk
$ svn commit -m “integer.c: ported r344 (spelling fixes) from trunk.”
$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk my-calc-branch
$ svn merge http://svn.example.com/repos/branch1@150 \
http://svn.example.com/repos/branch2@212 \
my-working-copy
$ svn merge -r 100:200 http://svn.example.com/repos/trunk my-working-copy
$ svn merge -r 100:200 http://svn.example.com/repos/trunk
$ svn merge –dry-run -r 343:344 http://svn.example.com/repos/calc/trunk

最后一条命令仅仅做合并测试,并不执行合并操作。

建立标签和建立分支没什么区别,不过是拷贝到不同的目录而已。

$ svn copy http://svn.example.com/repos/calc/trunk \
http://svn.example.com/repos/calc/tags/release-1.0 \
-m “Tagging the 1.0 release of the ‘calc’ project.”

$ ls
my-working-copy/
$ svn copy my-working-copy http://svn.example.com/repos/calc/tags/mytag
Committed revision 352.

后一种方式直接把本地的工作拷贝复制为标签。

此外,你还可以删除某个分支。

$ svn delete http://svn.example.com/repos/calc/branches/my-calc-branch \
-m “Removing obsolete branch of calc project.”

管理人员常用命令

(7) 版本库管理

$ svnadmin help

$ svnadmin help create

$ svnadmin create –fs-type bdb /usr/local/repository/svn/test
$ chown -R svn.svn /usr/local/repository/svn/test

建立版本库,库类型为bdb(使用Berkeley DB做仓库),库名称为test。
svn版本库有两种存储方式:基于Berkeley DB(bdb)或者基于文件系统(fsfs),通过 –fs-type可指定存储方式。

(8) 查询版本库信息

$ svnlook help

$ svnlook help tree

$ svnlook tree /usr/local/repository/svn/test –show-ids

关注微信公众号,手机阅读更方便: 程序员的阅微草堂

知识共享许可协议莿鸟栖草堂CFC4N 创作,采用 知识共享 署名-非商业性使用-相同方式共享(3.0未本地化版本)许可协议进行许可。基于http://www.cnxct.com上的作品创作。转载请注明转自:svn命令行使用说明(转)

发表评论

电子邮件地址不会被公开。 必填项已用*标注