Top Banner
淺淺淺淺淺淺淺淺 淺淺淺淺淺淺淺淺 淺淺淺淺淺淺淺淺淺淺淺淺 淺淺 Jim Huang ( 黃黃黃 ) http://jserv.sayya.org/ May 19, 2005
60
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Version Control Brief

淺談版本控制系統淺談版本控制系統

觀念介紹與版本控制系統軟體介紹

Jim Huang (黃敬群 )http://jserv.sayya.org/May 19, 2005

Page 2: Version Control Brief

目標 理解版本控制系統的重要性與優點,並如

何導入開發流程 版本控制系統軟體 Subversion 觀念與快速入門

Page 3: Version Control Brief

為何需要版本控制 (Version Control) ?

在需要協同開發 / 創作的環境中,確保能夠進行…保有所有更動的紀錄得以快速回復到特定版本的狀態得知成員的更動與其更動幅度

Code Peer review 鼓勵版本異動文件創作

Page 4: Version Control Brief

典型的版本變遷

RELEASE 1.0

RELEASE 1.5

RELEASE 2.0

C.I. 1

1.0

1.1

1.2

C.I. 2

1.0

C.I. 3

1.0

1.1

1.2

C.I. X

1.0

1.3

1.1

1.2

1.3

1.4

1.1

1.5

1.6

1.7

1.4

1.5

1.2

1.3

1.4

Page 5: Version Control Brief

軟體系統化管理

Configuration Builder

(Build scripting tool)

Tracker(Issue management)

Version Manager(Version control, Release

management)

Oracle,Sybase, etc.

Page 6: Version Control Brief

版本控制系統是什麼? 能夠追蹤、比較、回復、提交程式碼或文

件更動的系統,同時也要能夠跨越多個環境與群組開發時程的系統

維護並時 (concurrent) 的更動與保有每個版本的程式碼與文件狀態資訊

Page 7: Version Control Brief

版本控制系統 ( 集中化模式 )

A

Central RepositoryLocal Workspace(s)

A

Synchronization

Page 8: Version Control Brief

詞彙: Repository vs. Workspace workspace

一系列透過版本控制系統的程式碼與文件集合,開發者可以在本機上進行維護與修改的動作

repository 在集中式版本控制系統的主機上,保存文件與

程式碼的資料庫或檔案庫

Page 9: Version Control Brief

版本控制系統軟體 Commercial

Bitkeeper Visual SourceSafe

Open Source / Free SCCS RCS (Walter F. Tichy, 1982)

CVS (Brian Berliner & Jeff Polk, 1992)

GNU Arch Subversion (Karl Fogel, 2002)

SVK (clkao, 2004)

Page 10: Version Control Brief

CVS (Concurrent Version System) 歷久彌新 CVS 伺服器組態設定

Pserver relatively easy to configure on the client side, low

security

SSH high security, client & server configuration a bit

trickier

Page 11: Version Control Brief

CVS 優點 歷史悠久 在許多現有的軟體專案施行有年,系統穩

定,相關工具也豐富 設定與操作相對簡易

Page 12: Version Control Brief

CVS 缺點 Security! 不能移除目錄 二進位檔案有可能被修改 效率

Page 13: Version Control Brief

Subversion

CVS 的替代計畫,與 CVS 具有類似的操作方式與流程

多樣的伺服器配置方式:Apache web serversvnserve

custom serversvnserve & ssh

custom server with encryption layer

Page 14: Version Control Brief

Subversion 優點 目錄版本控制 不可分割的送交 網路傳輸快速 參數一致 更佳的二進制處理 高效率的分支與標記

Page 15: Version Control Brief

Subversion 缺點 仍然是集中式的版本控制系統 缺乏獨佔編輯權的設計 更動版本號是共用的

Page 16: Version Control Brief

SVK -- 非集中式版本控制系統 以 Subversion 為基礎,但是同時支援現

有 CVS 的 repository 可取出完整的更動映射 大量的合併操作

Page 17: Version Control Brief
Page 18: Version Control Brief

Subversion

集中式版本控制系統 (Centralized VCS) Released Feb. 2004, Open Source HTTP/WebDAV access “Better CVS” Graphical Client Tools

TortoiseSVN,..

Page 19: Version Control Brief

Subversion 系統架構 概念性的兩端

本機端檔案系統 Typically used for a single developer Accessed via direct file read/write

access Requires that users have local

accounts Uses filesystem and user/group

security 遠端系統

Accessed via a HTTP or HTTPS connection

Does not require that users have accounts on the server

Use Apache style authentication

Page 20: Version Control Brief

存取 Subversion 的途徑 Web - Browser

RO

WebDAV Mount Repository as

webfolder

SVN Client tool Local Repository copy

Page 21: Version Control Brief

Repository Resources

所有被 Subversion 管理的檔案與目錄都有唯一的 URL 表示法

支援的 URL protocolshttp, https (SSL encryption)

http://svn.csie.net/svn/prj/trunk/TopGun

protocol host repository directory

Page 22: Version Control Brief

獲得 Subversion 存取權限 可透過內建 (svn) 或 WebDAV 的方式認

證 Install/Use Client Software

BrowserWeb-Folder SupportTortoiseSVN (TortoiseSVN.tigris.org)

Page 23: Version Control Brief

TortoiseSVN

Subversion Client Windows Explorer

Extension

Page 24: Version Control Brief

Subversion 核心操作 Import/Checkout Update/Commit Branch/Tag Switch/Merge

Page 25: Version Control Brief

import

將本地端目錄結構新增至既有的 repository One time operation. 在本地端目錄被 import 後,需要再次 check out

確保其他開發者能夠存取到 import 的目錄

Page 26: Version Control Brief

Import

Central RepositoryLocal Workspace(s)

A

import

A

Central RepositoryLocal Workspace(s)

A

before

after

in sync

Page 27: Version Control Brief

Fort.f77

場景: work/fort.f77 即將透過 Subversion 管理

Page 28: Version Control Brief

import

Page 29: Version Control Brief

Check Repository

Use Web Browser in System

Use Repo-Browser in Tortoise

Page 30: Version Control Brief

Subversion 指示器 在檔案總管的目錄與檔案圖示就會有一個

打勾的符號 ‘.svn’ 目錄保有該版本資訊

Page 31: Version Control Brief

checkout

在本機檔案系統上,從 repository 取出文件與程式碼,並建立一份工作副本 (working copy)

One time operation. 給予工作副本來源屬性資訊 在開始工作的前置動作

Page 32: Version Control Brief

Checkout

Central RepositoryLocal Workspace(s)

checkout

A

Central RepositoryLocal Workspace(s)

A

before

after

in sync

A

Page 33: Version Control Brief

Checkout

Page 34: Version Control Brief

Local Work on fort.f77

場景:取出 fort.f77 並作修改 最後將 ‘ commit’ 到 repository

Page 35: Version Control Brief

commit

確保 workspace 與 repository 的一致與同步 (sync)

本地端的修改包含:文件與程式碼內容的修改、刪除,以及新增當開發者認為足以公布本地端修改到

repository 時

Page 36: Version Control Brief

commit

Central RepositoryLocal Workspace(s)

commit

A’

Central RepositoryLocal Workspace(s)

A’

before

after

in sync

A A’

Page 37: Version Control Brief

‘commit’ 的時機 最好能夠一次提交概念性、官能性,或者任務導向性的修改

至少確保原始程式碼還能通過編譯 更動記錄應該被保存在 commit 訊息中

Page 38: Version Control Brief

commit

Page 39: Version Control Brief

Subversion Revision Number Revision number 代表整個 repository 的

更動版本號並非只是本地端修改的版本號

“HEAD” 表示最新的版本

Page 40: Version Control Brief

歷史修改記錄 追蹤 revisions

版本號 作者 訊息 更動文件與檔案

Page 41: Version Control Brief

版本間的比較

比較特定 revision 與本地端版本的差異

Page 42: Version Control Brief

update

將 repository 上的版本整合到本地端的工作副本

將 workspace 同步於 repository有可能會出現衝突Subversion 會試圖作有限度的整合與提醒

Page 43: Version Control Brief

update

Central RepositoryLocal Workspace(s)

update

A’

Central RepositoryLocal Workspace(s)

A’

before

after

in sync

A’ A

Page 44: Version Control Brief

Update

檢驗 repository 相較於本機端的版本是否有修改?

Page 45: Version Control Brief

Check Log again! New revision 5 is

there.

Page 46: Version Control Brief

Do update!

Page 47: Version Control Brief

What is new ?

Page 48: Version Control Brief

切換到特定 Revision 需要回復到之前的版本

Page 49: Version Control Brief

哪些檔案應該置放於版本控制系統?

Source Code files*.c, *.cpp, *.java, *.for, *.txt, …

程式關連檔案,如:Build / Configuration filesDocumentationTest code + data sets

Page 50: Version Control Brief

What does not go into Subversion? 可由原始程式碼衍生的檔案暫時性或過渡性檔案

*.o; *.obj, *.dll, *.exe, *.dvi當然,有時候允許例外

很少需要重新產生 (regenerated) 的資訊檔不容易透過整合開發環境或現有工具再產生的項目

Page 51: Version Control Brief

可被 Subversion 忽略的檔案或目錄 目錄內的 Subversion:ignore

屬性可以告知 Subversion 忽略檔案與目錄的修改

Page 52: Version Control Brief

Branch

邏輯上來說,相較於現行發展線的獨立開發項目

“branch” 基本上是開始於某份工作副本,經過一番修改與維護,所展開的分支

Page 53: Version Control Brief

Branch 建立分支的時間點

某個開發者或團隊針對新的考量: 可能會對 main line 造成衝擊 衍生成為獨立的產品

Time

Main development line(e.g. RZWQM)

1st branch (e.g. RZWQM DSSAT)

2nd branch

branch

branch

Page 54: Version Control Brief

Branch

Page 55: Version Control Brief

Delete

在本機端工作副本與 repository 上移除檔案或目錄的操作

在 commit 之前,只會刪除本地端工作副本的檔案,而不會影響到 repository

Page 56: Version Control Brief

Repository Layout

trunk main development

code base

branches subproject branches

tags tagged releases

branchesbranches

tagstags

trunktrunk

//

rzwqmrzwqm

rzwqm-98rzwqm-98

rzwqm-depression

rzwqm-depression

Page 57: Version Control Brief

Branch 將分支間的差異套用到現行的工作副本

Time

Main development line(e.g. RZWQM)

1st branch (e.g. RZWQM DSSAT)

2nd branch

branch

branch

merge

merge

Page 58: Version Control Brief

Merge

“merge” 的時機整合 branch 之間的更動整合不同 branch 之間的加強與重大修正到

trunk建立新產品的修正項目

Page 59: Version Control Brief

參考資訊 Subversion

http://svnbook.red-bean.com/ http://tortoisesvn.tigris.org http://subversion.tigris.org

CVS Best Practices http://www.magic-cauldron.com/cm/cvs-bestpractices/

Version Control With Subversion http://svnbook.red-bean.com/svnbook-1.0/svn-book.html

Practicing Subversion within Debian Project http://www.deadbeast.net/~branden/svn_pres/top.html

Page 60: Version Control Brief

Questions?