Presentation is loading. Please wait.

Presentation is loading. Please wait.

An introduction to Subversion

Similar presentations


Presentation on theme: "An introduction to Subversion"— Presentation transcript:

1 An introduction to Subversion
Jiann-Ching Liu

2 上課前的準備 在 Windows 系統上抓陸龜並安裝 or 考慮安裝一個 SSH 的 Client 程式 [optional] 本投影片 PPT 檔 [optional]

3 Why Subversion 幫你做程式的版本控制及備份
多人開發系統時, 可以很方便的取得別人更新的部份 (lock-modify-unlock / copy-modify-merge) 更方便做到上線系統及測試系統的程式碼同步 避免程式只在客戶端, 而中心沒有備份 避免程式隨人員離職而帶走卻沒有備份 Subversion 開發團隊 上線系統 測試機

4 Subversion’s Architecture
CommandLine Client app GUI client apps Client Library Working copy management library Repository Access DAV SVN Local TCP/IP Network Apache mod_dav_svn svnserver Subversion Repository Berkeley DB FSFS

5 Repository Access URLs
file:// direct repository access (on local disk) access via WebDAV protocol to Subversion-aware Apache server same as but with SSL encryption. svn:// access via custom protocol to an svnserve server svn+ssh:// same as svn://, but through an SSH tunnel.

6 Basic Work Cycle Merge 有些小麻煩, 今天的介紹將不 Cover 這個 topic
• Update your working copy svn update • Make changes svn add svn delete svn copy svn move • Examine your changes svn status svn diff svn revert • Merge others' changes into your working copy svn update svn resolved • Commit your changes svn commit Merge 有些小麻煩, 今天的介紹將不 Cover 這個 topic

7 Basic Work Cycle initial import Local data Repository checkout
initial checkout Ver 1 Ver 1 update Ver 1 Commit Modify Ver 2 Ver 1m Ver 2 Commit Modify Ver 2m Ver 3

8 New 一個新 project 到 以 帳號登入後去 new 一個 project. 在 new 這個 project 時, 取一個易記的名稱, 這個名稱必須是英文/或數字的字串, 例如宿網系統可叫 dormnet 這個系統將自動建立一個獨立的 Repository, 位址在 或

9 規劃 Repository 的 structure
/trunk [read-write] 一般的開發使用 (直接放,裡面不要去分版本目錄) /branches [read-write] 某個 revision 的 copy (可做任意修改) /releases [read-write] 某個 revision 的 copy (只能做 bugfix) /tags [read-only] 某個 revision 的 copy (不能修改)

10 Layout Example / x trunk y z x1 Branch 1 y2 branches x2 Branch 2 y3 z1
releases x2 release-1.1 y2 z2 tags x1 release-1.0 y1

11 Repository with new copy

12 Login (使用 帳號密碼) 1 2

13 進行專案建立 1 2 3

14 建完儲存

15 Tips 最好是直接在你開發及服務的系統上使用 Subversion, 會比較方便 !!
可以考慮每天早上來做一次 update, 再開始改/寫程式, 下班做一次 commit. (對 trunk) 我們的 Lab 將帶各位在 Unix 下使用 Command line, Windows 下使用 GUI

16 Unix 安裝 Client 程式 Fedora (Linux) yum install subversion
FreeBSD cd /usr/ports/devel/subversion make install Solaris Source 安裝 Source Code:

17 安裝 Subversion (from source)
Openssl [optional] ( Berkeley DB ( Zlib ( apr/apr-util ( Apache [optional] ( Neon (v0.25.5) ( Subversion (

18 Unix 的 Lab 可用 sparc19 或 sparc20 做練習
這個 Lab 是假設你有一個 Web ap, URL 是 1. 將你的 Web ap 做 Initial import 2. 將你的 Web ap 做 initial checkout 3. 你的 Web ap 有檔案做了修改 (請同步到 repository) 4. 你的 Web ap 有新增檔案 (請同步到 repository) 為方便起見, 你可以在 sparc19/sparc20 執行下列指令來下載這個 Lab 的範例 cd mkdir –p public_html/svnlab cd public_html/svnlab wget tar xvf svnlab.tar

19 Lab Unix Lab 2/10 Unix 的 Lab (conti.) 先用瀏覽器看一下你的 Web ap 及 Repository 的現況. 網址分別是 Revision 1: /trunk .. Powered by Subversion version (r19776).

20 第一次, 出現一些惱人的畫面, 輸入 p (permanently) 及密碼
Lab Unix Lab 3/10 Unix 的 Lab (conti.) 做 initial import cd ~/public_html/svnlab svn import release -m “Initial import” 用瀏覽器觀察 第一次, 出現一些惱人的畫面, 輸入 p (permanently) 及密碼 svn import release -m "Initial import" Error validating server certificate for ' - The certificate is not issued by a trusted authority. Use the fingerprint to validate the certificate manually! Certificate information: - Hostname: turtle.cc.ncu.edu.tw - Valid: from Aug 16 08:49: GMT until Aug 23 08:49: GMT - Issuer: Certificate Authority, National Central University, Chung Li, Taiwan, TW - Fingerprint: 07:b0:41:0b:56:05:93:5d:75:38:dd:7e:6d:a5:6d:c9:0a:ac:f3:09 (R)eject, accept (t)emporarily or accept (permanently? p Authentication realm: < Subversion repository Password for 'center5': Adding (bin) release/dzh_header.gif Adding release/index.html Committed revision 2.

21 Lab Unix Lab 4/10 Unix 的 Lab (conti.) 用瀏覽器觀察 接下來, 一定要做一次 initial checkout, 而不是直接繼續開發 (否則 subversion 無法追蹤你的程式異動) Revision 變成 2 Revision 2: /trunk .. dzh_header.gif index.html Powered by Subversion version (r19776). 程式碼已經丟上來嘍

22 Unix 的 Lab (conti.) Unix Lab 5/10 Lab
做 initial checkout cd ~/public_html/svnlab svn checkout 用 ls –l 觀察一下, 發現多了一個 trunk 的目錄 [~/public_html/svnlab] 81: ls –l total 36 drwxr-xr-x 2 center5 man Dec 8 14:22 release -rw-r--r-- 1 center5 man Dec 8 13:28 svnlab.tar drwxr-xr-x 3 center5 man Dec 8 14:35 trunk drwxr-xr-x 2 center5 man Dec 8 13:26 update svn checkout A trunk/dzh_header.gif A trunk/index.html Checked out revision 2. 很順利, 連密碼都沒問 ~~ 很方便, 但 …. 密碼被偷存起來了 !!

23 Lab Unix Lab 6/10 Unix 的 Lab (conti.) 現在, release 目錄已經沒用了, 把 release 目錄刪掉, 把 trunk 目錄改成 release 刪掉!! 太可怕了, 你可以先 tar 起來做個備份, 並比較一下 release 與 trunk 目錄有何不同 [~/public_html/svnlab] 89: tar jcvpf release.tar.bz2 release release/ release/index.html release/dzh_header.gif [~/public_html/svnlab] 90: diff -r -u release trunk Only in trunk: .svn [~/public_html/svnlab] 91: mv release release-save; mv trunk release [~/public_html/svnlab] 92: rm -fr release-save 如果是一個上線的系統, 指令一氣呵成, 讓轉換時間減少到最小 勇敢的把它殺了 !! Trunk 在每個子目錄多了 .svn 的隱藏目錄, 記載一些資訊 !! Think Twice !! : 如果你的目錄有一些特殊 的 file ownership 或 permission 的設定 !!

24 Unix 的 Lab (conti.) Unix Lab 7/10 Lab
現在 release 目錄已經是 checkout 出來的版本, 現在要對現有的檔案做點修改 如果你懶得改, 你可以 copy update 目錄下的 index.html 覆蓋 release 目錄的 index.html 就當作你已經做了修改, 這個動作如下 [~/public_html/svnlab] 98: cp -i update/index.html release cp: overwrite `release/index.html'? Y [~/public_html/svnlab] 99: 為了測試一下多人開發, 更新的問題, 我們再 checkout 一份做為比對 (跟剛剛 checkout 一樣, 直接就留在 trunk 目錄) 當你修改好時, 到 release 目錄下做 svn diff 可以先觀察, 做 svn update 看是否有人已做了更新, 最後做 svn commit [~/public_html/svnlab] 105: cd release [~/public_html/svnlab/release] 106: svn update At revision 2. [~/public_html/svnlab/release] 107: svn diff …. …. [~/public_html/svnlab/release] 108: svn commit -m 'modify a little bit‘ Sending index.html Transmitting file data . Committed revision 3. [~/public_html/svnlab/release] 108:

25 Unix 的 Lab (conti.) Unix Lab 8/10 Lab
剛剛我們在 commit 之前, checkout 一個版本在 trunk 目錄, 想像這是另一個開發者, 要如何取得最新的版本 … 沒錯, 用 svn update [~/public_html/svnlab/release] 110: cd ../trunk/ [~/public_html/svnlab/trunk] 111: svn update U index.html Updated to revision 3. [~/public_html/svnlab/trunk] 112: 現在, 我們在 Web ap 裡, 要加一個程式或文件, 你可以在 release 目錄去加, 或是直接複製 update 目錄下的 info.php 當做新加的程式. [~/public_html/svnlab/trunk] 114: cd ../release [~/public_html/svnlab/release] 115: cp ../update/info.php . [~/public_html/svnlab/release] 116: 將這個 info.php 程式加進來 [~/public_html/svnlab/release] 116: svn add info.php A info.php [~/public_html/svnlab/release] 117: 做 commit [~/public_html/svnlab/release] 118: svn commit -m 'add info.php‘ Adding info.php Transmitting file data . Committed revision 4. [~/public_html/svnlab/release] 119:

26 Lab Unix Lab 9/10 Unix 的 Lab (conti.) 用瀏覽器觀察 相對於 svn add 的指令 svn delete, 請自行測試. Revision 變成 4 Revision 4: /trunk .. dzh_header.gif index.html info.php Powered by Subversion version (r19776). Info.php 出現了

27 Lab Unix Lab 10/10 Unix 的 Lab (conti.) 如何做一個 branch 或一個 release, 其實很簡單, svn copy [~/public_html/svnlab/release] 122: svn copy -m "Release 1.0" Committed revision 5. [~/public_html/svnlab/release] 123: 請用瀏覽器去觀察 release 目錄 Lab 結束,不玩了 … 但!! 剛剛密碼好像被 svn 記住了 ~~ rm -fr ~/.subversion 可以讓它忘了一切 在同一行哦

28 TortoiseSVN 用 Windows 開發的可以鬆一口氣, 因為陸龜比海龜還容易 …
可以到 抓陸龜 安裝很簡單 …

29 Tortoise 上做 Import 1 在要 Import 的資料夾按右鍵 2 選 TortoiseSVN 3 做 Import

30 Import 2 1 3 心情好時, 可以輸入一些資訊 輸入正確的網址 完成 import
參考網址是

31 Initial checkout 先 new 一個資料夾 按右鍵選 “SVN Checkout”
鍵入 Repository 的 URL, 再輸出帳號及密碼即可 Checkout 出來的資料夾會有一個打綠色勾的符號, 資料夾裡的檔案 icon 也會有同樣情形 (參見下頁的 screenshot) 資料夾有個 .svn 的隱藏目錄 系統的開發工作目錄由原先 import 的目錄, 改為現在 checkout 出來的目錄

32 Screenshot

33 修改及新增檔案 在新的工作目錄 (由 SVN checkout 出來的那個) 上對現存檔案做修改, 這個檔案的 icon 會由原先綠色打勾的狀態變成紅色驚嘆號的狀態 新增檔案至工作目錄, 則該檔案沒有任何 SVN 的標記

34 Screenshot

35 Commit 按右鍵選 SVN Commit 出現右圖
陸龜察覺 index.html 已被修改, 另外那個 New Text Document 是新加進來的 (需點選才會加到 SVN)

36 做出一份 Release 點滑鼠右鍵,選 TortoiseSVN, 再選 repo-browser
輸入 Repository 的 URL 出現 Repository Browser 如圖 點 trunk 按右鍵選 Copy to 打上欲複製到的 URL, 如:

37 Resources Subversion http://subversion.tigris.org/
TortoiseSVN / TortoiseMerge Version Control with Subversion (E-Book)


Download ppt "An introduction to Subversion"

Similar presentations


Ads by Google