一,svn分支與合并有什麼用?
作程式的,對svn在熟悉不過了,但對svn分支熟悉的,我想并不多。因為一般情況下,是用不着svn分支的,其實也沒有那個必要。下面我例舉幾個需要用到svn分支的情況:
1,比較大的項目。比較大的項目,一般情況下會分成幾個階段來完。好比什麼五年計劃。到了某個階段時,我建立一個分支,當個備份。萬一将來開發下個階段東西的時候,出現緻命錯誤的時候,我還能把這個分支拿出來接着用。
2,項目要開發新的東西,但是又不想和主幹沖突,建立一個分支,單獨做為一個開發分支。這樣做也是為了責任明确。如果出了問題也好有所查證。
二,建立svn分支
1,建立一個代碼檔案夾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,建立分支
[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
A /main
A /main/test.php
4,注間事項:
a),建立分支,隻能在同一個倉庫内進行,跨倉庫是不行的。會提示svn: No repository found in
'svn://127.0.0.1'
b),建立分支時,注意加上注釋,不然會報以下錯誤。
[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
三,合并分支
下面講一個例子,來說明怎麼合并分支。我覺得通過例子,最能讓人學到東西了,我在我的博文一在強調這一點。
1,修改main中的檔案送出到svn伺服器端,這樣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個版本
U test.php
[root@BlackGhost branch]# svn log -v test.php //檢視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
A /main
A /main/test.php
[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 //是沒因為沒有送出,送出後會産生一個新的版本
r9 | zhangy | 2010-10-24 20:52:22 +0800 (Sun, 24 Oct 2010) | 1 line
M /branch
M /branch/test.php
到這兒合并基本上就結束了。
3,上面說的是将主幹的檔案同步到分支中去,把分支的内容同步步主幹也是一樣的,倒過來就行了。
4,全并的時候,有可能會沖突的,看下面
[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
+=======
+222222222222
+
+>>>>>>> .merge-right.r12
來自連接配接:http://blog.csdn.net/heihuifeng/article/details/7525932