一,,svn分支與合并有什么用?
作程序的,,對(duì)svn在熟悉不過了,,但對(duì)svn分支熟悉的,,我想并不多,。因?yàn)橐话闱闆r下,,是用不著svn分支的,其實(shí)也沒有那個(gè)必要,。下面我例舉幾個(gè)需要用到svn分支的情況:
1,,比較大的項(xiàng)目。比較大的項(xiàng)目,,一般情況下會(huì)分成幾個(gè)階段來完,。好比什么五年計(jì)劃。到了某個(gè)階段時(shí),,我建立一個(gè)分支,,當(dāng)個(gè)備份。萬一將來開發(fā)下個(gè)階段東西的時(shí)候,,出現(xiàn)致命錯(cuò)誤的時(shí)候,,我還能把這個(gè)分支拿出來接著用。
2,,項(xiàng)目要開發(fā)新的東西,,但是又不想和主干沖突,建立一個(gè)分支,,單獨(dú)做為一個(gè)開發(fā)分支,。這樣做也是為了責(zé)任明確。如果出了問題也好有所查證,。
二,,創(chuàng)建svn分支
在說創(chuàng)建分支前,關(guān)于svn的安裝和配置,,請(qǐng)參考linux svn安裝和配置,,不結(jié)合apache
1,創(chuàng)建一個(gè)代碼文件夾main
[root@BlackGhost repos]# pwd
/home/zhangy/checkout/repos
[root@BlackGhost repos]# svn add ./main
A main
A main/test.php
[root@BlackGhost repos]# svn commit ./main -m "test"
Adding main
Adding main/test.php
Transmitting file data .
Committed revision 5.
2,,創(chuàng)建分支
[root@BlackGhost repos]# svn copy svn://127.0.0.1/repos/main svn://127.0.0.1/repos/branch -m "test"
Committed revision 6.
3,,查看分支情況
[root@BlackGhost repos]# svn log -v ./branch/test.php
------------------------------------------------------------------------
r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
A /branch (from /main:5)
test
------------------------------------------------------------------------
r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
Changed paths:
A /main
A /main/test.php
test
------------------------------------------------------------------------
4,注間事項(xiàng):
a),,創(chuàng)建分支,,只能在同一個(gè)倉(cāng)庫(kù)內(nèi)進(jìn)行,跨倉(cāng)庫(kù)是不行的,。會(huì)提示svn: No repository found in 'svn://127.0.0.1'
b),,創(chuàng)建分支時(shí),注意加上注釋,,不然會(huì)報(bào)以下錯(cuò)誤,。
[root@BlackGhost repos]# svn cp svn://127.0.0.1/repos/main svn://127.0.0.1/repos/branch
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found
三,合并分支
下面講一個(gè)例子,,來說明怎么合并分支,。我覺得通過例子,最能讓人學(xué)到東西了,,我在我的博文一在強(qiáng)調(diào)這一點(diǎn),。
1,,修改main中的文件提交到svn服務(wù)器端,這樣main的代碼就和branch分支的代碼就不一樣了,。
2,,把main文件中的文件同步到分支中branch中
- [root@BlackGhost branch]# pwd //是否在分支的文件夾中
- /home/zhangy/checkout/repos/branch
- /**
- 把main的修改同步到branch分支中
- 如果是指定版本的可以svn merge -r 9:10 svn://127.0.0.1/repos/main
- */
- [root@BlackGhost branch]# svn merge svn://127.0.0.1/repos/main
- --- Merging r6 through r8 into '.': //更新到第8個(gè)版本
- U test.php
- [root@BlackGhost branch]# svn log -v test.php //查看test.php,從下面我們可以看出,,分支版本還是沒有變?yōu)槭裁茨兀?/span>
- ------------------------------------------------------------------------
- r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
- Changed paths:
- A /branch (from /main:5)
- test
- ------------------------------------------------------------------------
- r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
- Changed paths:
- A /main
- A /main/test.php
- test
- ------------------------------------------------------------------------
- [root@BlackGhost branch]# svn commit -m "test" //提交
- Sending .
- Sending test.php
- Transmitting file data .
- Committed revision 9.
- [root@BlackGhost branch]# svn log -v test.php //是沒因?yàn)闆]有提交,,提交后會(huì)產(chǎn)生一個(gè)新的版本
- ------------------------------------------------------------------------
- r9 | zhangy | 2010-10-24 20:52:22 +0800 (Sun, 24 Oct 2010) | 1 line
- Changed paths:
- M /branch
- M /branch/test.php
- test
- ------------------------------------------------------------------------
- r6 | zhangy | 2010-10-24 19:59:35 +0800 (Sun, 24 Oct 2010) | 1 line
- Changed paths:
- A /branch (from /main:5)
- test
- ------------------------------------------------------------------------
- r5 | zhangy | 2010-10-24 19:53:20 +0800 (Sun, 24 Oct 2010) | 1 line
- Changed paths:
- A /main
- A /main/test.php
- test
- ------------------------------------------------------------------------
到這兒合并基本上就結(jié)束了。
3,,上面說的是將主干的文件同步到分支中去,,把分支的內(nèi)容同步步主干也是一樣的,倒過來就行了,。
4,,全并的時(shí)候,有可能會(huì)沖突的,,看下面
- [root@BlackGhost main]# svn merge svn://127.0.0.1/repos/branch
- Conflict discovered in 'test.php'. //提示有沖突
- Select: (p) postpone, (df) diff-full, (e) edit, //在這里讓你選擇處理方式
- (mc) mine-conflict, (tc) theirs-conflict,
- (s) show all options: p
- --- Merging r7 through r12 into 'test.php':
- C test.php
- Summary of conflicts:
- Text conflicts: 1 //雖然有沖突,,但是還是可以同步了,也說明同步成功了,。
- --- /tmp/tempfile.2.tmp Sun Oct 24 21:02:11 2010
- +++ .svn/tmp/test.php.tmp Sun Oct 24 21:02:11 2010
- @@ -0,0 +1,9 @@
- +<<<<<<< .working
- +asdfadfadfadf
- +111111111111111
- +=======
- +asdfadfadfadf
- +111111111111111
- +222222222222
- +
- +>>>>>>> .merge-right.r12