svn命令 通常都有帮助,可通过如下方式查询:
$ svn help
知道了子命令,但是不知道子命令的用法,还可以查询:
$ svn help add
<br />
开发人员常用命令
(1) 导入项目
$ cd ~/project<br />$ mkdir -p svntest/{trunk,branches,tags}<br />$ svn import svntest https://localhost/test/svntest --message "Start project"<br />...<br />$ 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<br /># shows the last change committed to foo.c<br /><br />$ svn log --revision HEAD<br /># shows log message for the latest repository commit<br /><br />$ svn diff --revision HEAD<br /># compares your working file (with local changes) to the latest version<br /># in the repository<br /><br />$ svn diff --revision BASE:HEAD foo.c<br /># compares your “pristine” foo.c (no local changes) with the <br /># latest version in the repository<br /><br />$ svn log --revision BASE:HEAD<br /># shows all commit logs since you last updated<br /><br />$ svn update --revision PREV foo.c<br /># rewinds the last change on foo.c<br /># (foo.c's working revision is decreased)<br /><br />$ svn checkout --revision 3<br /># specified with revision number<br /><br />$ svn checkout --revision {2002-02-17}<br />$ svn checkout --revision {15:30}<br />$ svn checkout --revision {15:30:00.200000}<br />$ svn checkout --revision {"2002-02-17 15:30"}<br />$ svn checkout --revision {"2002-02-17 15:30 +0230"}<br />$ svn checkout --revision {2002-02-17T15:30}<br />$ svn checkout --revision {2002-02-17T15:30Z}<br />$ svn checkout --revision {2002-02-17T15:30-04:00}<br />$ svn checkout --revision {20020217T1530}<br />$ svn checkout --revision {20020217T1530Z}<br />$ svn checkout --revision {20020217T1530-0500}
(3) 日常指令
$ svn update<br /><br />$ svn add foo.file<br />$ svn add foo1.dir<br />$ svn add foo2.dir --non-recursive<br />$ svn delete README<br />$ svn copy foo bar<br />$ svn move foo1 bar1<br /><br />$ svn status<br />$ svn status --verbose<br />$ svn status --verbose --show-updates<br />$ svn status stuff/fox.c<br /><br />$ svn diff<br />$ svn diff > patchfile<br /><br />$ svn revert README<br />$ svn revert
修改冲突发生时,会生成三个文件:.mine, .rOLDREV, .rNEWREV。比如:
$ ls -l<br />sandwich.txt<br />sandwich.txt.mine<br />sandwich.txt.r1<br />sandwich.txt.r2
解决修改冲突方式之一:修改冲突的文件sandwich.txt,然后运行命令:
$ svn resolved sandwich.txt
方式之二:用库里的新版本覆盖你的修改:
$ cp sandwich.txt.r2 sandwich.txt<br />$ svn resolved sandwich.txt
方式之三:撤销你的修改,这种方式不需要运行resolved子命令:
$ svn revert sandwich.txt<br />Reverted 'sandwich.txt'<br />$ ls sandwich.*<br />sandwich.txt
确保没问题后,就可以提交了。
$ svn commit --message "Correct some fatal problems"<br />$ svn commit --file logmsg<br />$ svn commit
(4) 检验版本历史
$ svn log<br />$ svn log --revision 5:19<br />$ svn log foo.c<br />$ svn log -r 8 -v<br /><br />$ svn diff<br />$ svn diff --revision 3 rules.txt <br />$ svn diff --revision 2:3 rules.txt <br />$ svn diff --revision 4:5 http://svn.red-bean.com/repos/example/trunk/text/rules.txt<br /><br />$ svn cat --revision 2 rules.txt <br />$ svn cat --revision 2 rules.txt > rules.txt.v2<br /><br />$ svn list http://svn.collab.net/repos/svn<br />$ svn list --verbose http://svn.collab.net/repos/svn<br /><br />$ svn checkout --revision 1729 # Checks out a new working copy at r1729<br />…<br />$ svn update --revision 1729 # Updates an existing working copy to r1729<br />…
(5) 其他有用的命令
svn cleanup
为失败的事务清场。
(6) 分支和合并
建立分支方法一:先checkout然后做拷贝,最后提交拷贝。
$ svn checkout http://svn.example.com/repos/calc bigwc<br />A bigwc/trunk/<br />A bigwc/trunk/Makefile<br />A bigwc/trunk/integer.c<br />A bigwc/trunk/button.c<br />A bigwc/branches/<br />Checked out revision 340.<br /><br />$ cd bigwc<br />$ svn copy trunk branches/my-calc-branch<br />$ svn status<br />A + branches/my-calc-branch<br /><br />$ svn commit -m "Creating a private branch of /calc/trunk."<br />Adding branches/my-calc-branch<br />Committed revision 341.
建立分支方法二:直接远程拷贝。
$ svn copy http://svn.example.com/repos/calc/trunk \<br /> http://svn.example.com/repos/calc/branches/my-calc-branch \<br /> -m "Creating a private branch of /calc/trunk."<br /><br />Committed revision 341.
建立分支后,你可以把分支checkout并继续你的开发。
$ svn checkout http://svn.example.com/repos/calc/branches/my-calc-branch
假设你已经checkout了主干,现在想切换到某个分支开发,可做如下的操作:
$ cd calc<br />$ svn info | grep URL<br />URL: http://svn.example.com/repos/calc/trunk<br />$ svn switch http://svn.example.com/repos/calc/branches/my-calc-branch<br />U integer.c<br />U button.c<br />U Makefile<br />Updated to revision 341.<br />$ svn info | grep URL<br />URL: http://svn.example.com/repos/calc/branches/my-calc-branch
合并文件的命令参考:
$ svn diff -r 343:344 http://svn.example.com/repos/calc/trunk<br />$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk<br />$ svn commit -m "integer.c: ported r344 (spelling fixes) from trunk."<br />$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk my-calc-branch<br />$ svn merge http://svn.example.com/repos/branch1@150 \<br /> http://svn.example.com/repos/branch2@212 \<br /> my-working-copy<br />$ svn merge -r 100:200 http://svn.example.com/repos/trunk my-working-copy<br />$ svn merge -r 100:200 http://svn.example.com/repos/trunk<br />$ svn merge --dry-run -r 343:344 http://svn.example.com/repos/calc/trunk
最后一条命令仅仅做合并测试,并不执行合并操作。
建立标签和建立分支没什么区别,不过是拷贝到不同的目录而已。
$ svn copy http://svn.example.com/repos/calc/trunk \<br /> http://svn.example.com/repos/calc/tags/release-1.0 \<br /> -m "Tagging the 1.0 release of the 'calc' project."<br /><br />$ ls<br />my-working-copy/<br />$ svn copy my-working-copy http://svn.example.com/repos/calc/tags/mytag<br />Committed revision 352.
后一种方式直接把本地的工作拷贝复制为标签。
此外,你还可以删除某个分支。
$ svn delete http://svn.example.com/repos/calc/branches/my-calc-branch \<br /> -m "Removing obsolete branch of calc project."
管理人员常用命令
(7) 版本库管理
$ svnadmin help<br />...<br />$ svnadmin help create<br />...<br />$ svnadmin create --fs-type bdb /usr/local/repository/svn/test<br />$ chown -R svn.svn /usr/local/repository/svn/test
建立版本库,库类型为bdb(使用Berkeley DB做仓库),库名称为test。<br />svn版本库有两种存储方式:基于Berkeley DB(bdb)或者基于文件系统(fsfs),通过 --fs-type可指定存储方式。
(8) 查询版本库信息
$ svnlook help<br />...<br />$ svnlook help tree<br />...<br />$ svnlook tree /usr/local/repository/svn/test --show-ids<br />
<br>
<br>