SVN分支
Branch 選項會給開發者創建出另外一條線路。當有人希望開發進程分開成兩條不同的線路時,這個選項會非常有用。
比如專案 demo 下有兩個小組,svn 下有一個 trunk 版。
由於客戶需求突然變化,導致專案需要做較大改動,此時專案組決定由小組 1 繼續完成原來正進行到一半的工作(某個模組),小組 2 進行新需求的開發。
那麼此時,我們就可以為小組2建立一個分支,分支其實就是 trunk 版(主幹線)的一個copy版,不過分支也是具有版本控制功能的,而且是和主幹線相互獨立的,當然,到最後我們可以通過(合併)功能,將分支合併到 trunk 上來,從而最後合併為一個專案。
我們在本地副本中創建一個 my_branch 分支。
root@zaixian:~/svn/zaixian01# ls branches tags trunk root@zaixian:~/svn/zaixian01# svn copy trunk/ branches/my_branch A branches/my_branch root@zaixian:~/svn/zaixian01#
查看狀態:
root@zaixian:~/svn/zaixian01# svn status A + branches/my_branch A + branches/my_branch/HelloWorld.html A + branches/my_branch/readme
提交新增的分支到版本庫。
root@zaixian:~/svn/zaixian01# svn commit -m "add my_branch" Adding branches/my_branch Replacing branches/my_branch/HelloWorld.html Adding branches/my_branch/readme Committed revision 9.
接著我們就到 my_branch 分支進行開發,切換到分支路徑並創建 index.html 檔。
root@zaixian:~/svn/zaixian01# cd branches/my_branch/ root@zaixian:~/svn/zaixian01/branches/my_branch# ls HelloWorld.html index.html readme
將 index.html 加入版本控制,並提交到版本庫中。
root@zaixian:~/svn/zaixian01/branches/my_branch# svn status ? index.html root@zaixian:~/svn/zaixian01/branches/my_branch# svn add index.html A index.html root@zaixian:~/svn/zaixian01/branches/my_branch# svn commit -m "add index.html" Adding index.html Transmitting file data . Committed revision 10.切換到 trunk,執行 svn update,然後將 my_branch 分支合併到 trunk 中。
root@zaixian:~/svn/zaixian01/trunk# svn merge ../branches/my_branch/ --- Merging r10 into '.': A index.html --- Recording mergeinfo for merge of r10 into '.': G .
此時查看目錄,可以看到 trunk 中已經多了 my_branch 分支創建的 index.html 檔。
root@zaixian:~/svn/zaixian01/trunk# ll total 16 drwxr-xr-x 2 root root 4096 Nov 7 03:52 ./ drwxr-xr-x 6 root root 4096 Jul 21 19:19 ../ -rw-r--r-- 1 root root 36 Nov 7 02:23 HelloWorld.html -rw-r--r-- 1 root root 0 Nov 7 03:52 index.html -rw-r--r-- 1 root root 22 Nov 7 03:06 readme
將合併好的 trunk 提交到版本庫中。
root@zaixian:~/svn/zaixian01/trunk# svn commit -m "add index.html" Adding index.html Transmitting file data . Committed revision 11.