開發中項目的版本管理和svn使用(下)

上篇主要介紹了版本管理,下篇會寫一下svn工具的使用,會覆蓋svn的基本使用方法,重點在分支管理上。

svn的基本使用方法

相信很多程序員每天到公司的第一件事情就是打開編譯器同步代碼,把最新的代碼下載到本地;每天的最後一件事情也很有可能是向svn/git提交最新代碼關電腦回家。暫時沒有使用過git,整理一下svn使用的基本方法吧。

在eclipse上安裝svn插件

公司自行開發的前端開發插件不支持在Idea上使用,所以全公司的開發工具幾乎都是eclipse……….(這是一句吐槽)
首先安裝eclipse,在官網上下載最新安裝包安裝一路next即可。然後是安裝插件,有兩種方法。其一是使用eclipse自帶的功能安裝:help—>install new software,在打開的新窗口裏填上name:subclipse,url:http://subclipse.tigris.org/update_1.10.x;然後點擊add,都選上,一路next即可。但是由於網路環境各種原因,這個安裝方式失敗的機率是很高的….第二種方式就是直接從url:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 下載,然後解壓,將壓縮包features和plugins目錄中的文件分別複製到Eclipse安裝目錄的features和plugins中,重啓即可。

svn更新和提交

這是兩個最基本動作。只要記得在更新和提交之前先同步代碼,確認有沒有衝突即可。

svn衝突代碼解決

新手很容易因爲代碼衝突丟失代碼,我也幹過這事兒…..同理,請慎重使用”更新並覆蓋本地代碼“選項,因爲這麼一操作,本地修改也會被覆蓋掉,消失得無影無蹤。
衝突代碼產生的原因是多人同時修改同一個文件,並且提交。一旦產生代碼衝突是不能直接提交代碼的,必須先解決衝突才能正常提交。
解決方式是這樣的:對於有代碼衝突的文件,選擇更新操作,此時本地會出現這麼幾個文件:

  • a.java 待處理的文件
  • a.java.mine 本地修改的文件
  • a.java.r(xxx+1) 服務器最新版本
  • a.java.r(xxx) 本地修改的基礎版本(服務器取下的版本)

這時候手動處理“a.Java”,得到一個合併的最新版本,然後右擊Team->標記爲解決。默認選擇第一個“標記爲衝突解決”,點擊OK。剛纔的三個文件將消失,剩下自己的源文件。這時候就可以提交了

svn分支的拉取和合並

開發中版本管理是必不可少的,每多一個支線就新開一個分支,每當一個支線完成開發就合併一個分支。

svn代碼建立分支

在eclipse中選擇項目,右擊Team–>Branch/Tag,在彈出窗口的“到 Url”填入新分支的url,選擇ok即可。
這裏寫圖片描述

svn代碼代碼合併(merge)

merge的選項

svn合併

代碼合併相對於建立分支稍微複雜一點,你從哪個項目上點擊這個目錄,那個項目就是目標,而填入的url就是被merge的分支。假如我們在trunk上點擊merge,填入branches上的一個url,那麼上面菜單對應的意思就是:

  • 將branches的部分修改合併到trunk上
  • 將branches的全部修改合併到trunk上
  • 將trunk上的修改合併到branches。
  • 合併2個分支到主幹,需要填入兩個branches的地址,當然也可以填一個branches和trunk
  • 從branches到trunk,手動鎖定部分不需要合併的代碼
  • 從branches到trunk,解鎖部分已經鎖定的代碼
    英文不是很好,還是貼上每個選項自帶的英文解釋,有心的可以再看看

  • Use this method to catch-up a feature branch with the changes in trunk or another branch. You can merge a specific set of revisions or all eligible revisions

  • Use this method to merge the changes in feature branch to trunk or the location the branch was created from. To use this method the working copy must not hava any local modifications.It must be at a revision of the working copy must be greater than or equal to the last recision the branch was synchronized to
  • Use this method to merge the rivisions associated with one or more CollabNet artifacts. Typically this option would be used to backport fixes to a release branch or similiar scenarios where all of the changes associated with an artifact need to be merged from one location to another
  • Use this method to merge the differences between two URL and revision pair into the current location. This could be used as an alternative to the reintegrate merge scenario when you want to control the specific path and revisions that are being compared for the merge input
  • use this method to block a revision or range of revisions from being merged into this location. For example,you might want to do this if the changes in the branch have already been manually applied to this location or you do not intend to ever merge the changes form the branch into this location
  • Use this method to unlock a revison or range of revision that have previously been blocked from this location.You might also use this option to manually remove the record of some revisions having been merged so that they can be merged again.

那麼我們一般的使用方式就是從branches合併代碼到trunk,自己對應選擇上面的選項就可以了。

merge的兩個常見錯誤

  1. no uncommited modified :表示當前版本還有沒有提交的文件,如果不需要提交就選擇revert.需要提交就先提交代碼,再merge就可以了
  2. working copy at a single version:表示當前目錄沒有從SVN服務器更新最新的版本。update下後在操作就行了。
發佈了34 篇原創文章 · 獲贊 17 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章