用 Subversion 來維護程式

西元 2004 年 11 月 12 日 凌晨 2 點 38 分





最近在實驗室寫 project 和幫朋友改 bbs 的聊天室,都是用 Subversion 來維護產出的程式碼。

簡單來講,Subversion 採用 Global Revision Numbers,不像其它版本控制系統 (ex: CVS) 是針對每個個別的檔案做版本控制,檔案的版本只會在有修改 commit (提交) 時才會遞增。對 Subversion 來說,在你每次 commit (新增、修改或刪除任何檔案或任何資料夾) 時,Subversion 會遞增 Global Revision Number,而每個檔案和資料夾只會記住它在哪幾個 global revision 裡也有被修改到。所以,你日後要 checkout 時所指定的版本編號所代表的意義是:「整個 repository 在第 N 次 commit 後的狀態」。當然,你 checkout 時所指定的 repository URL 除了可以指定整個 repository 的根目錄,也可以只指定一個檔案或 repository 裡的目錄。

我想這對一般人來講才是比較直覺的,而不像 CVS 是對每個 repository 裡的檔案分別做版本編號,如果要推出一個 release 版本時,需要對所有檔案做 tag 標記,如此一來,CVS 才知道每個檔案要使用第幾版。

我在 Windows 平台上使用的 Subversion Client 是 TortoiseSVN,這是免費的,它把 Subversion client 應有的功能都整合在 Windows 檔案總管的右鍵選單裡,相當的便利。 :)

安裝 Subversion
Subversion 我安裝在 Fedora Core 2,用 Fedora 內附的 up2date 即可馬上安裝完成,只要打

up2date --install subversion

就可以了,注意要使用 root 來執行這個命令。

設定原始碼的維護成員
一開始先確定哪些系統上的 user 需要參與同一個專案的原始碼維護工作,在這裡假設有 user_a、user_b 和 user_c,把這些帳號加到新成立的 project_a group (/etc/group 檔案):

lteamster:x:30055:user_a,user_b,user_c

設定 Subversion repository
在這裡我們建立 /home/project_a 這個目錄,並把初始化這個目錄為 Subversion repository:

svnadmin create /home/project_a

Subversion 會在指定目錄下建立一些 Subversion 系統使用的檔案。接下來就是設定這個 repository 的存取權限,把 repository 目錄和裡面的檔案設定只有其 owner 和 project_a group 成員可以存取 (rw)。

chown -R user_a.project_a /home/project_a
chmod 770 /home/project_a
chmod -R g+w /home/project_a

設定這個 repository 的存取權限,把下面三行加進去 /home/project_a/conf/svnserve.conf:

[general]
anon-access = none
auth-access = write

anon-access 是限制匿名登入 (使用 svn:// 連線) 的存取權限,我們設為 none,也就是不能讀寫 (checkout 和 commit)。而 auth-access 是限制有援權的使用者 (使用 svn+ssh:// 來登入) 的存取權限,我們設為 write,也就是可以讀寫。

使用 Subversion
最後就可以在 Windows 上用 TortoiseSVN 來 import 資料到 repository,Repository’s URL 輸入:

svn+ssh://username@svn-server-ip-address/home/project_a

username 改成你在 svn-server-ip-address 這台電腦使用的帳號名稱,svn-server-ip-address 是 Subversion server 的主機 IP 位址,緊接在IP 後面的是 repository 在系統的路徑。接下來就可以開始使用 Subversion 來維謢程式碼了。Enjoy It!

備份 Subversion repository

dump: usage: svnadmin dump REPOS_PATH [-r LOWER[:UPPER]] [--incremental]

Dump the contents of filesystem to stdout in a ‘dumpfile’ portable format, sending feedback to stderr. Dump revisions LOWER rev through UPPER rev. If no revisions are given, dump all
revision trees. If only LOWER is given, dump that one revision tree. If –incremental is passed, then the first revision dumped will be a diff against the previous revision, instead of the usual fulltext.

Valid options:
-r [--revision] arg : specify revision number ARG (or X:Y range)
–incremental : dump incrementally
-q [--quiet] : no progress (only errors) to stderr

回復 Subversion repository

load: usage: svnadmin load REPOS_PATH

Read a ‘dumpfile’-formatted stream from stdin, committing
new revisions into the repository’s filesystem. If the repository
was previously empty, its UUID will, by default, be changed to the
one specified in the stream. Progress feedback is sent to stdout.

Valid options:
-q [--quiet] : no progress (only errors) to stderr
–ignore-uuid : ignore any repos UUID found in the stream
–force-uuid : set repos UUID to that found in stream, if any
–parent-dir arg : load at specified directory in repository

後來因為常常得直接在 Linux command line 下改程式,所以 commit 程式到 Subversion 也直接在 command line 下完成,svn ci 可以 commit 程式碼, svn co 是 checkout 程式碼,svn st 可以看目前 working copy 的修改狀態,要回復程式碼到上一個版本用 svn revert,回復時不需要再連到 Subversion 就可以完成。其它詳細內容請見 manual。 :)

相關連結
Subversion revision 10061 (Manual)
http://svnbook.red-bean.com/svnbook/book.html

Subversion Draft Revision 1411M (中文化 manual)
http://twpug.net/docs/Subversion/

TortoiseSVN
http://tortoisesvn.tigris.org/







24 則留言 @ “用 Subversion 來維護程式”

頁數: « 1 2 [3]

  1. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    To Miels:
    Server 版?到 Subversion 官方網站下載就有了呀。 :)

  2. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    請問:
    如果我 import 專案時, 有一些檔案格式並沒有被加入, 要如何將這些沒有被加入的檔案格式, 加入到預設支援的檔案格式設定檔中(或者說: 我要如何找到這個設定檔, 然後去編輯欲加入或不欲加入的檔案格式)?
    謝謝.

  3. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    To jackie:
    據我所知 Subversion 似乎沒有一個設定檔是用來控制哪些檔案格式預設要被 import,所以你只能在 import 完專案之後再手動新增這些檔案進去 repository 吧? :)

  4. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    請問Subversion svn+ssh:// 應該如何使用呢?

  5. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    To josh:
    在 Windows 或是 Mac OS X 下的終端機用 ssh 指令即可。 ;)

  6. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    [...] http://sanwangx.brain-c.com/archives/2004_11/12_153/ http://www.seety.org/technote/programming/svn_intro January 10, 2007 · 程式設計 · [...]

  7. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    我想請問為什麼我點
    Subversion Draft Revision 1411M (中文化 manual)
    出現無此網頁

    可以跟我說正確的網址嗎
    謝謝

  8. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    To Sam:
    失效的連結,換這個吧。 :)

    http://twpug.net/docs/Subversion/

  9. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    Dear Sir:

    可否請教您一個問題,就是checkout 可以只checkout 單一檔案嗎,因為我試著用TortoiseSvn
    checkout 單一file,就會出現如下的error
    Error URL”http://subver.test.com/svn/d2k/ECS/schema/ctm1101.tab’ refers to
    a file,not a directory

    那這要在那裡改設定,還是就真的只能checkout folder 而以..

  10. MyAvatars 0.2 MyBlogLog
    Gravatar

    (這是什麼?)

    To 希希:
    當然可以 checkout 單一檔案啊,不過你這個錯誤訊息我沒有遇過,你可以按文件再重新產生一次 repository,或是重新 checkout 出來整個 repository,或是再用 Google 多找找這個錯誤訊息是怎麼一回事,祝你好運! :)

頁數: « 1 2 [3]

留個言吧!