svn命令详解

SVN 介绍:

在项目目录下有三个目录
a) trunk--------主干, 线上环境运行的就是这个代码.
b) branches----分支, 仅限开发, 合并使用. 通常是以项目名字命名子目录,一般在aone上新建的小需求时,aone就会自动新建分支.
c) tags---------标记 aone一般用来合并发布当天所有和这个代码模块相关的小需求代码,然后统一进行编绎

我们接触最多的是branches,branches开发工程师可以申请读写权限,trunk我们是没有写权限的,只有读权限。
常用SVN命令:

最全的还是使用svn help命令
在命令行中输入svn help,会显示svn 的所有子命令及全局参数;
在命令行中输入svn help commond 会显示commond 的使用方法及参数; 如svn help ci

1.新拉分支命令:

应用场景:
a.当有代码模块有新的发布时,主干上有更新,需要从主干上新拉分支,将当前开发分支的代码合并到新的分支上去,以保持开发分支上的代码与主干是一致
b.当有新的功能点要开发,而不想与其它功能点在一起互相影响,需要从主干上新拉分支
*命令格式:*svn copy trunk_url branch_url -m "comments"
执行路径:在命令行的任意路径执行均可
参数说明:
trunk_url:一般是从主干上新拉分支
branch_url:分支地址 分支的命令方式,一般是日期_分支功能点_num 当然,这个名字很灵活了,最好的是能让人一眼看出这个分支是做什么功能点用的,num是1 2 3 。。。
*例如:*给测试同学测试多域名分支用的拉分支命令:
svn copy http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/trunk/
http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110805_test_multi-domain_1
-m "20110805_test_multi-domain_1 from trunk for test :多域名"

2.从svn 中检出代码到本地工作空间

应用场景:需要在本地跑应用,或是查看代码,你懂的。
命令格式:svn co URL[@REV]... [PATH]
执行路径:在本地想要存放代码的路径中执行
参数说明:
URL[@REV]:想要检出的代码URL路径 REV是版本号,如果不写REV,则默认检出最新代码
PATH:如果不写Path,则url的最后一段将作为文件夹名称(分支名称)
例如:将分支20110805_test_multi-domain_1的代码co到本地 当前路径:
svn co http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110805_test_multi-domain_1 .<这里有个点哟>


3.查看svn 提交记录:

应用场景:需要查看指定分支的修改记录
命令格式:
svn log [PATH] 显示本地 PATH (默认: ".") 的日志信息。默认的版本范围是 BASE:1
svn log URL[@REV] [PATH...] 显示 URL 中 PATH (默认: ".") 的日志信息。默认的版本范围是 BASE:1
执行路径:如果没有PATH参数 ,则需要在本地工作拷贝所在路径执行; 如果指定了URL,在任意路径均可执行
*有个特别的参数:--stop-on-copy:*日志一直打到当前分支从日志主干上拉下来为止,这个很有用的哟
-l num :看num条
-v:查看每条修改记录中,都有哪些文件改动过了
例如:查看分支20110802_68007_multi-domain_7从分支开始创建到最新代码之前所有的日志
svn log http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110802_68007_multi-domain_7 --stop-on-copy

查看分支20110802_68007_multi-domain_7的最新三条日志
svn log http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110802_68007_multi-domain_7 -l 3

查看分支20110802_68007_multi-domain_7的最新一条日志,并查看都有哪些文件被修改过了
svn log http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110802_68007_multi-domain_7 -l 1 -v


4.合并代码命令:

例如:
svn merge -r 32129:head http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110802_68007_multi-domain_7 --dry-run

执行路径:想要合并到的目标分支所co到本地的路径
如想将20110802_68007_multi-domain_7上的32129到最新版本的所有修改合并到20110805_test_multi-domain_1上,本地先将20110805_test_multi-domain_1的代码co到${user.home}/work/intl-iris下,然后,在${user.home}/work/intl-iris下运行svn merge 命令

有个特别的参数:--dry-run,就是预合一下,并未真正的将改动合并到本地,一般可以使用这个命令查看一下有哪些文件会合并进来,有没有冲突的文件
如果不加--dry-run,则改动合并到本地工作拷贝了
5.查看当前工作拷贝有哪些修改:

命令格式:svn st [PATH...]
如果不指定path,则是查看当前目录与svn上最新代码相比较的修改,如果指定path,则查看指定路径下的修改。

执行路径:当前工作拷贝路径下 

具体返回的文件状态的值,可以查看一下:http://b2b-doc.alibaba-inc.com/pages/viewpage.action?pageId=14616374
6.提交修改的代码:

命令格式:svn ci -m 'comments' [PATH...]
提交代码时,一定要写comments,以说明这次是什么修改,如果是合并代码的提交,要按如下格式书写:
Merging 20110802_68007_multi-domain_7 r32130 through r33590 into 20110805_test_multi-domain_1
含义即为:20110802_68007_multi-domain_7这个分支上r32130 到 r33590 的修改合并到了分支20110805_test_multi-domain_1上

如果不指定path,则将当前目录下的所有修改提交到SVN
执行路径:如果指定绝对path,则可以在任意路径下执行,如果不指定path,或是指定的是相对路径,则需要在工作拷贝路径下执行。

请注意,如果是想要合并代码,如果有staus为C(冲突)的,测试同学一定要联系开发同学帮助合并,解决冲突。因为状态为conflict时,svn 是不允许提交的

同时,请养成一个习惯,先从svn库上更新最新的代码 (svn up),再提交,以免提交时,出现冲突
7.将冲突标记为解决:

命令格式:svn reloved [path...]
将冲突的文件标记为解决,svn 在收到这个命令后,会将本地因冲突产生的三个新文件删除。如果不指定Path ,会将当前目录及子目录下所有冲突状态的文件标记为解决

切记:提交前,如果工作空间下有冲突的文件,一定要先解决冲突,再将文件标记为己解决,最后再提交
8.切换分支:

命令格式:svn sw url
切换到指定分支中,在切换时,本地的修改不会丢失,但是svn 地址会切换到新路径下

*执行路径:*本地工作拷贝路径,如果不在正确的路径运行该命令,会失败的
例如:svn sw http://svn.alibaba-inc.com/repos/ali_sourcing/apps/web/intl-iris/branches/20110805_test_multi-domain_1

svn help st

$ svn help st
status (stat, st): Print the status of working copy files and directories.
usage: status [PATH...]

  With no args, print only locally modified items (no network access).
  With -q, print only summary information about locally modified items.
  With -u, add working revision and server out-of-date information.
  With -v, print full revision information on every item.

  The first seven columns in the output are each one character wide:
     First column : Says if item was added, deleted, or otherwise changed
      ' ' no modifications
      'A' Added
      'C' Conflicted
      'D' Deleted
      'I' Ignored
      'M' Modified
      'R' Replaced
      'X' an unversioned directory created by an externals definition
      '?' item is not under version control
      '!' item is missing (removed by non-svn command) or incomplete
      '~' versioned item obstructed by some item of a different kind
    Second column: Modifications of a file's or directory's properties
      ' ' no modifications
      'C' Conflicted
      'M' Modified
    Third column: Whether the working copy directory is locked
      ' ' not locked
      'L' locked
    Fourth column: Scheduled commit will contain addition-with-history
      ' ' no history scheduled with commit
      '+' history scheduled with commit
    Fifth column: Whether the item is switched or a file external
      ' ' normal
      'S' the item has a Switched URL relative to the parent
      'X' a versioned file created by an eXternals definition
    Sixth column: Repository lock token
      (without -u)
      ' ' no lock token
      'K' lock token present
      (with -u)
      ' ' not locked in repository, no lock token
      'K' locked in repository, lock toKen present
      'O' locked in repository, lock token in some Other working copy
      'T' locked in repository, lock token present but sTolen
      'B' not locked in repository, lock token present but Broken
    Seventh column: Whether the item is the victim of a tree conflict
      ' ' normal
      'C' tree-Conflicted
    If the item is a tree conflict victim, an additional line is printed
    after the item's status line, explaining the nature of the conflict.

  The out-of-date information appears in the ninth column (with -u):
      '*' a newer revision exists on the server
      ' ' the working copy is up to date

  Remaining fields are variable width and delimited by spaces:
    The working revision (with -u or -v)
    The last committed revision and last committed author (with -v)
    The working copy path is always the final field, so it can
      include spaces.

  Example output:
    svn status wc
     M     wc/bar.c
    A  +   wc/qax.c

    svn status -u wc
     M           965    wc/bar.c
           *     965    wc/foo.c
    A  +         965    wc/qax.c
    Status against revision:   981

    svn status --show-updates --verbose wc
     M           965       938 kfogel       wc/bar.c
           *     965       922 sussman      wc/foo.c
    A  +         965       687 joe          wc/qax.c
                 965       687 joe          wc/zig.c
    Status against revision:   981

    svn status
     M      wc/bar.c
    !     C wc/qaz.c
          >   local missing, incoming edit upon update
    D       wc/qax.c

Valid options:
  -u [--show-updates]      : display update information
  -v [--verbose]           : print extra information
  -N [--non-recursive]     : obsolete; try --depth=files or --depth=immediates
  --depth ARG              : limit operation by depth ARG ('empty', 'files',
                            'immediates', or 'infinity')
  -q [--quiet]             : print nothing, or only summary information
  --no-ignore              : disregard default and svn:ignore property ignores
  --incremental            : give output suitable for concatenation
  --xml                    : output in XML
  --ignore-externals       : ignore externals definitions
  --changelist ARG         : operate only on members of changelist ARG
                             [aliases: --cl]

Global options:
  --username ARG           : specify a username ARG
  --password ARG           : specify a password ARG
  --no-auth-cache          : do not cache authentication tokens
  --non-interactive        : do no interactive prompting
  --trust-server-cert      : accept unknown SSL server certificates without
                             prompting (but only with '--non-interactive')
  --config-dir ARG         : read user configuration files from directory ARG
  --config-option ARG      : set user configuration option in the format:

你可能感兴趣的:(svn命令详解)