5. svn linux 客户端的使用

在 linux环境中使用svn  客户端。

客户端指令 就是svn

[root@localhost ~]# svn --help
usage: svn <subcommand> [options] [args]
   add
   blame (praise, annotate, ann)
   cat
   changelist (cl)
   checkout (co)                                             # 拉取版本,简写co
   cleanup
   commit (ci)                                               # 提交,简写ci
   copy (cp)
   delete (del, remove, rm)
   diff (di)
   export
   help (?, h)
   import
   info
   list (ls)
   lock
   log
   merge
   mergeinfo
   mkdir
   move (mv, rename, ren)
   patch
   propdel (pdel, pd)
   propedit (pedit, pe)
   propget (pget, pg)
   proplist (plist, pl)
   propset (pset, ps)
   relocate
   resolve
   resolved
   revert
   status (stat, st)
   switch (sw)
   unlock
   update (up)                                             #从服务端同步文件
   upgrade

Subversion is a tool for version control.
For additional information, see http://subversion.apache.org/

拉取代码

svn  checkout  svn://192.168.134.174:/sadoc    /svndata/   --username=test02   --password=123456
svn代码库地址 本地地址,目录提前创建 用户名 密码

svn  co   svn://192.168.134.174:/sadoc    /svndata/   --username=test02   --password=123456
指令简写

查看回显,以下就完成了。

[root@localhost svndata]# svn  checkout  svn://192.168.134.174:/sadoc    /svndata/   --username=test02   --password=123456

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.134.174:3690> 934c0447-3ff6-4c11-a195-53e3e8f43666

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
A    test02.txt
Checked out revision 5.
[root@localhost svndata]# ls
test02.txt

如果svn的  服务端和  客户端在一台机器上面 。   可以使用以下url访问  (基本不用)。

[root@localhost datatest]# ps -ef  | grep   svn                                                      # svn  服务端和客户端 在一台机器上面
root       1204      1  0 11:08 ?        00:00:00 /usr/bin/svnserve -d -r /application/svndata/
root       1234   1161  0 11:26 pts/0    00:00:00 grep --color=auto svn
[root@localhost datatest]# svn  co  file:///application/svndata/sadoc/  /datatest/                   # 使用指令   密码都不用       
A    test02.txt
A    test03.txt
Checked out revision 6.
[root@localhost datatest]# ls
test02.txt  test03.txt

报错处理:

如果同步数据的数据出现报错

svn: Can't convert string from 'UTF-8' to native encoding

是字符集的问题, windows是支持中文的。 linux装系统的时候默认不支持中文。

可以参考:

https://www.cnblogs.com/zhaobolu/archive/2014/04/02/3641309.html

修改~/.bashrc,加入
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

然后
source ~/.bashrc

然后检查下语言环境

[root@localhost svndata]# locale
LC_CTYPE="en_US.UTF-8"                    #用户所使用的语言符号及其分类
LC_NUMERIC="en_US.UTF-8"                  #数字
LC_TIME="en_US.UTF-8"                     #时间显示格式
LC_COLLATE="en_US.UTF-8"                  #比较和排序习惯
LC_MONETARY="en_US.UTF-8"                 #货币单位
LC_MESSAGES="en_US.UTF-8"                 #信息主要是提示信息,错误信息, 状态信息, 标题, 标签, 按钮和菜单等
LC_PAPER="en_US.UTF-8"                    #默认纸张尺寸大小
LC_NAME="en_US.UTF-8"                     #姓名书写方式
LC_ADDRESS="en_US.UTF-8"                  #地址书写方式
LC_TELEPHONE="en_US.UTF-8"                #电话号码书写方式
LC_MEASUREMENT="en_US.UTF-8"              #度量衡表达方式
LC_IDENTIFICATION="en_US.UTF-8"           #对自身包含信息的概述

其中两个比较特殊的

LANG                #系统语言
LC_ALL              #如果设置,值将覆盖所有其他的locale设定

同步更新

svn update   /svndata/
本地路径

看回显

[root@localhost svndata]# svn update   /svndata/
Updating '.':
A    test03.txt                                            #  A 就是增加
Updated to revision 6.
[root@localhost svndata]# ls
test02.txt  test03.txt

查看数据

可以使会用   svn list

[root@localhost svndata]# svn  list  /svndata/         
本地路径
[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc
远程库
[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc  --verbose (显示详细信息)

提交数据

使用指令的话。svn的提交也是需要 先add   然后在 commit的

单个文件提交

[root@localhost svndata]# touch {a..d}                               #  先创建了几个文件 
[root@localhost svndata]# ls
a  b  c  d  test02.txt  test03.txt
[root@localhost svndata]# svn  add  a # 单个文件提交
A         a
[root@localhost svndata]# svn  ci # ci 就是 commit的缩写。 一定要加 -m 参数,写提交信息。 不加会报错
svn: E205007: Commit failed (details follow):
svn: E205007: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: E205007: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found
[root@localhost svndata]# svn  ci  -m  "add  a" # 加上 -m参数就ok了
Adding         a
Transmitting file data .
Committed revision 9.
[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc #再次查看 ,文件已经提交了。
a
test02.txt
test03.txt

批量提交

[root@localhost svndata]# svn add  *                                                     #  文件多的话,可以使用* ,  但是已经提交过文件,会告警
svn: warning: W150002: '/svndata/a' is already under version control
A         b
A         c
A         d
svn: warning: W150002: '/svndata/test02.txt' is already under version control
svn: warning: W150002: '/svndata/test03.txt' is already under version control
svn: E200009: Could not add all targets because some targets are already versioned
svn: E200009: Illegal target for the requested operation
[root@localhost svndata]# 
[root@localhost svndata]# 
[root@localhost svndata]# 
[root@localhost svndata]# svn commit -m  "add  files"                                  #  再次提交
Adding         b
Adding         c
Adding         d
Transmitting file data ...
Committed revision 10.
[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc                      #  查看版本库,已经生效了。
a b c d test02.txt test03.txt

然后我们去windows上去查看,远程的库信息。 也可以看到文件已经提交了。

导入本地目录到svn库

这里的导入,不是在库里面创建文件提交。 而是,使用其他路径下的目录或文件导入进去。

[root@localhost svndata]# mkdir  -p    /tmp/svn/trunk    /tmp/svn/brunch    /tmp/svn/logs                       # 创建了三个文件   类似于git的  master 、 brunch、log的目录
[root@localhost svndata]# tree  /tmp/svn/
/tmp/svn/
├── brunch
├── logs
└── trunk

[root@localhost svndata]# svn import  /tmp/svn/  svn://192.168.134.174:/sadoc  -m  "add  new  dirs" # 使用import进行导入 , 也是必须要加上 -m 参数的 。
Adding         /tmp/svn/brunch
Adding         /tmp/svn/trunk
Adding         /tmp/svn/logs

Committed revision 11.
[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc # 查看一下就有了
a
b
brunch/
c
d
logs/
test02.txt
test03.txt
trunk/

复制目录

就是将svn库中的目录,复制一下。用的不多

[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc                                                # 查看当前的目录结构  
a
b
brunch/
c
d
logs/
test02.txt
test03.txt
trunk/
[root@localhost svndata]# svn copy    svn://192.168.134.174:/sadoc/trunk    svn://192.168.134.174:/sadoc/brunch/new_brunch_2019    -m  "copy dir " # 使用copy指令,就是从哪复制到哪 ,也是必须要加上 -m 参数的 。
Committed revision 12.
[root@localhost svndata]# svn  list  svn://192.168.134.174:/sadoc/brunch/ # 再次查看,可以看到生效了
new_brunch_2019

然后我们去windows上面看 ,也可以看到目录结构。

猜你喜欢

转载自www.cnblogs.com/rockyricky/p/12123868.html