SVN usage

The original address for details: http://www.roncoo.com/article/detail/124725
1. Check out

svn co http://path (full path of directory or file) [full path of local directory] --username username --password password

svn co svn://path (full path of directory or file) [full path of local directory] --username username --password password

svn checkout http://path (full path of directory or file) [full path of local directory] --username username

svn checkout svn://path (full path of directory or file) [full path of local directory] --username username

Note: If the password is transmitted without the --password parameter, you will be prompted to enter the password. It is recommended not to use the --password option in clear text.

  There are two short lines before username and password, not one.

  If the full path of the local directory is not specified, it will be checked out to the current directory.

example:

svn co svn://localhost/testtools/home/testtools --username wzhnsc

svn co http://localhost/test/testapp --username wzhnsc

svn checkout svn://localhost/testtools/home/testtools --username wzhnsc

svn checkouthttp://localhost/test/testapp --username wzhnsc

 

2. Export (export a clean directory tree without the .svn folder)

svn export [-r version number] http://path (full path of directory or file) [full path of local directory] --username username

svn export [-r version number] svn://path (full path of directory or file) [full path of local directory] --username username

svn export The full path of the locally checked out directory (that is, with the .svn folder) The full path of the local directory to be exported

Note: The first form of exporting a clean working directory tree from the repository is to specify the URL,

   If a revision number is specified, the corresponding version is exported,

   If no revision is specified, the latest will be exported to the specified location.

   If the full path to the local directory is omitted, the last part of the URL will be used as the name of the local directory.

  The second form is to specify the full path of the locally checked out directory to the full path of the local directory to be exported, and all local modifications will be preserved.

   But files that are not under version control (ie, new files that are not committed, because there is no record of information about them in the .svn folder) will not be copied.

example:

svn export svn://localhost/testtools/home/testtools --username wzhnsc

svn export svn://localhost/test/testapp --username wzhnsc

svn export /home/testapp /home/testtools

 

3. Add a new file 

svn add filename

Note: Tell the SVN server to add files, and use svn commint -m to upload them in real!

example:

svn add test.php <- add test.php 

svn commit -m "add my test with test.php" test.php

svn add *.php <- add all php files in the current directory

svn commit -m "add all php files for my tests" *.php

 

4. Submit

svn commit -m "commit remark info text" [-N] [--no-unlock] filename

svn ci -m "commit remark info text" [-N] [--no-unlock] filename

Must take the -m parameter, the parameter can be empty, but must write -m

example:

svn commit -m “提交当前目录下的全部在版本控制下的文件“ * <- 注意这个*表示全部文件

svn commit -m “提交我的测试用test.php“ test.php

svn commit -m “提交我的测试用test.php“ -N --no-unlock test.php <- 保持锁就用–no-unlock开关

svn ci -m “提交当前目录下的全部在版本控制下的文件“ * <- 注意这个*表示全部文件

svn ci -m “提交我的测试用test.php“ test.php

svn ci -m “提交我的测试用test.php“ -N --no-unlock test.php <- 保持锁就用–no-unlock开关

 

5、更新文件

svn update

svn update -r 修正版本 文件名

svn update 文件名

例子:

svn update <- 后面没有目录,默认将当前目录以及子目录下的所有文件都更新到最新版本

svn update -r 200 test.cpp <- 将版本库中的文件 test.cpp 还原到修正版本(revision)200

svn update test.php <- 更新与版本库同步。

            提交的时候提示过期冲突,需要先 update 修改文件,

            然后清除svn resolved,最后再提交commit。

 

6、删除文件

svn delete svn://路径(目录或文件的全路径) -m “删除备注信息文本”

推荐如下操作:

svn delete 文件名 

svn ci -m “删除备注信息文本”

例子:

svn delete svn://localhost/testapp/test.php -m “删除测试文件test.php”

推荐如下操作:

svn delete test.php 

svn ci -m “删除测试文件test.php”

 

7、加锁/解锁 

svn lock -m “加锁备注信息文本“ [--force] 文件名 

svn unlock 文件名

例子:

svn lock -m “锁信测试用test.php文件“ test.php 

svn unlock test.php

 

8、比较差异 

svn diff 文件名 

svn diff -r 修正版本号m:修正版本号n 文件名

例子:

svn diff test.php<- 将修改的文件与基础版本比较

svn diff -r 200:201 test.php<- 对 修正版本号200 和 修正版本号201 比较差异

 

9、查看文件或者目录状态

svn st 目录路径/名

svn status 目录路径/名<- 目录下的文件和子目录的状态,正常状态不显示 

             【?:不在svn的控制中;  M:内容被修改;C:发生冲突;

              A:预定加入到版本库;K:被锁定】 

svn  -v 目录路径/名

svn status -v 目录路径/名<- 显示文件和子目录状态

              【第一列保持相同,第二列显示工作版本号,

               第三和第四列显示最后一次修改的版本号和修改人】 

注:svn status、svn diff和 svn revert这三条命令在没有网络的情况下也可以执行的,

  原因是svn在本地的.svn中保留了本地版本的原始拷贝。 

 

10、查看日志

svn log 文件名

例子:

svn log test.php<- 显示这个文件的所有修改记录,及其版本号的变化 

 

11、查看文件详细信息

svn info 文件名

例子:

svn info test.php

 

12、SVN 帮助

svn help <- 全部功能选项

svn help ci <- 具体功能的说明

 

13、查看版本库下的文件和目录列表 

svn list svn://路径(目录或文件的全路径)

svn ls svn://路径(目录或文件的全路径)

例子:

svn list svn://localhost/test

svn ls svn://localhost/test <- 显示svn://localhost/test目录下的所有属于版本库的文件和目录 

 

14、创建纳入版本控制下的新目录

svn mkdir 目录名

svn mkdir -m "新增目录备注文本" http://目录全路径

例子:

svn mkdir newdir

svn mkdir -m "Making a new dir." svn://localhost/test/newdir 

注:添加完子目录后,一定要回到根目录更新一下,不然在该目录下提交文件会提示“提交失败”

svn update

注:如果手工在checkout出来的目录里创建了一个新文件夹newsubdir,

  再用svn mkdir newsubdir命令后,SVN会提示:

  svn: 尝试用 “svn add”或 “svn add --non-recursive”代替?

  svn: 无法创建目录“hello”: 文件已经存在

  此时,用如下命令解决:

  svn add --non-recursive newsubdir

  在进入这个newsubdir文件夹,用ls -a查看它下面的全部目录与文件,会发现多了:.svn目录

  再用 svn mkdir -m "添hello功能模块文件" svn://localhost/test/newdir/newsubdir 命令,

  SVN提示:

  svn: File already exists: filesystem '/data/svnroot/test/db', transaction '4541-1',

  path '/newdir/newsubdir '

 

15、恢复本地修改 

svn revert [--recursive] 文件名

注意: 本子命令不会存取网络,并且会解除冲突的状况。但是它不会恢复被删除的目录。

例子:

svn revert foo.c <- 丢弃对一个文件的修改

svn revert --recursive . <-恢复一整个目录的文件,. 为当前目录 

 

16、把工作拷贝更新到别的URL 

svn switch http://目录全路径 本地目录全路径

例子:

svn switch http://localhost/test/456 . <- (原为123的分支)当前所在目录分支到localhost/test/456

 

17、解决冲突 

svn resolved [本地目录全路径]

例子:

$ svn update

C foo.c

Updated to revision 31.

如果你在更新时得到冲突,你的工作拷贝会产生三个新的文件:

$ ls

foo.c

foo.c.mine

foo.c.r30

foo.c.r31

当你解决了foo.c的冲突,并且准备提交,运行svn resolved让你的工作拷贝知道你已经完成了所有事情。

你可以仅仅删除冲突的文件并且提交,但是svn resolved除了删除冲突文件,还修正了一些记录在工作拷贝管理区域的记录数据,所以我们推荐你使用这个命令。

 

18、不checkout而查看输出特定文件或URL的内容 

svn cat http://文件全路径

例子:

svn cat http://localhost/test/readme.txt

19、新建一个分支copy

svn copy branchA branchB  -m "make B branch" // 从branchA拷贝出一个新分支branchB

20、合并内容到分支merge

svn merge branchA branchB  // 把对branchA的修改合并到分支branchB

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326822538&siteId=291194637
svn