歡迎您光臨本站 註冊首頁

svn 常用命令詳解

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0
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:
                                 FILE:SECTION:OPTION=[VALUE]
                  & nbsp;          For example:
                                 servers:global:http-library=serf

[火星人 ] svn 常用命令詳解已經有640次圍觀

http://coctec.com/docs/service/show-post-387.html